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!

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.