“解析错误:语法错误,”[关闭]中的意外T_FUNCTION

Why do I get this "Parse error: syntax error, unexpected T_FUNCTION in upload2.php on line 5" from this snippet:

<?php
$title = "Click to see the picture in full size";

$images = glob('./images/*.*', GLOB_BRACE); 
usort($images, function($a, $b) {  
return filemtime($a) < filemtime($b);  
});

foreach($images as $image) {
echo '<a href="'.$image.'"><img src="'.$image.'" width="430px" height="350px"    title="'.$title.'"></a>';
}

?>

It is working fine when I am using XAMPP localhost. Thanks in advance!

You are running different versions of PHP. Your local version supports anonymous functions (5.3+) but your production version does not.

The anonymous function syntax you're using on this line:

usort($images, function($a, $b) {  

is only available in PHP 5.3 and later. Your server is probably running PHP 5.2, which does not support this.

You will need to define the function separately and reference it by name, e.g.

function sort_by_mtime($a, $b) {
    ...
}

usort($images, "sort_by_mtime");