Possible Duplicate:
can't access global variables inside a usort function?
I’ve experienced this problem more then one time now, and I this time I couldnt figure out how to get around it.
$testing = "hej";
function compare($b, $a)
{
global $testing;
echo '<script>alert(\'>'.$testing.'<\');</script>';
}
Why does this not show a alertbox with “>hej<“, for me it shows “><“.
Also, this is a function that is call from uasort as second parameter.
The answer is simple: don’t use globals.
If you want access to that variable, and to change the value of that variable, pass it as a parameter by reference:
If you just want the value, pass it by value:
Update:
Another option is to pass an object to
usort()in an array: