Jump to content

Parse error: syntax error, unexpected T_FUNCTION


kektex

Recommended Posts

Just from searching the board I realize this has been asked sooo many times, but I can't seem to locate the problem in this code:

 


usort($status, function($a, $b) {global $sort; return strcmp($a[$sort], $b[$sort]); });

foreach(array_merge(array($cols), $status) as $line)
    call_user_func_array('printf', array_merge(array($fmt), $line));
print_r($print);

 

I'm getting a  " Parse error: syntax error, unexpected T_FUNCTION in ui.php " on the first line of this script.

 

The weird thing is that when I run the script on my PC using EasyPHP I don't get the error, it only happens on my Linux server.

 

Any ideas?

 

Thanks!

 

Anonymous functions are defined by the arguement string, then the code string.

The syntax would look like this

$func_name = create_function(args_string, code_string);

 

An example could be..

$myvariable = '1';
$myfunction = create_function('$myvariable', '$myvariable * 2');

echo $myfunction;

The result should be 2

 

Here is an example using usort().

$function = create_function('$a, $b', 'return(strlen($a) - strlen($b));');
$array = array('a massive string', 'it', 'huge length', 'cat poop');
usort($array, $function);
print_r($array);

 

I'm not saying this will work or not, but it's an example. I hope you understand!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.