Copy link to clipboard
Copied
I'm having a problem trying to understand why a predefined array is not being echoed/print_r when requested from inside a function.
the array is global(?) by being defined outside the function(s). I can't seem to see why it wont show the array?
It works outside the function
$mondayset=array("setone", "settwo", "setthree", "setfour");
$tuesdayset=array(""setfive", "setsix", setseven");
function dosets ($pubdate)
{
$caledardate = explode("/", $pubdate);
$timestamp = strtotime("$caledardate[2]"."-"."$caledardate[0]"."-"."$caledardate[1]");
if(date('D', $timestamp) === 'Mon')
{
echo "It is Monday today\n";
print_r($mondayset);
}
$thedate = 12/2/2013
dosets($thedate)
Variables inside functions have a local scope.
http://php.net/manual/en/language.variables.scope.php
You can pass the array to the function if you want to reference it.
Copy link to clipboard
Copied
Variables inside functions have a local scope.
http://php.net/manual/en/language.variables.scope.php
You can pass the array to the function if you want to reference it.
Copy link to clipboard
Copied
Wow Ok that link worked. got ot to work thanks!
Copy link to clipboard
Copied
Great. You're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now