Reputation: 1
I am getting the parse error: "syntax error, unexpected T_FUNCTION" when calling uksort()
with an anonymous callback function.
uksort($actions, function($a, $b) {
if (strlen($a) == strlen($b)) {
return 0;
}
if (strlen($a) > strlen($b)) {
return -1;
}
return 1;
}
What's wrong here?
Upvotes: -2
Views: 199
Reputation: 2790
function cmp($a, $b){
if(strlen($a) == strlen($b)) {
return 0;
}
if(strlen($a) > strlen($b)) {
return -1;
}
return 1;
}
uksort( $actions, "cmp" );
You cannot use closures because your version must be newer or equal 5.3
...
That's the reason why you have to pass the function name as a string ;)
Upvotes: 0
Reputation: 522523
You are running a version of PHP older than 5.3, in which anonymous functions did not exist.
Upvotes: 0