I have:
<?php
$a=array('x'=>3,'y'=>6,'z'=>12); //NOTE THIS*** position 1
echo func(5);
function func($c)
{
$a = array('x'=>3,'y'=>6,'z'=>12); //NOTE THIS*** position 2
$previous = null;
foreach($a as $k => $v)
{
if($v > $c) // This part was unclear, so it could be >= instead
{
return $previous;
}
$previous = $k;
}
return $previous;
}
Now, when I have the array $a inside the function (position 2), it works perfect. However, when I place $a outside the function (position 1) it does not work.
Why is this?