Derfder
Derfder

Reputation: 3324

Code that works on my localhost (PHP 5.3.4) is not working on older PHP environment on live server (PHP 5.2.17)

This is my code that is working nice on my localhost:

<?php
$list = array();
array_map(function($var){}, $matches_array_1);
foreach ( $matches_array_1 as $value ) {
    $key = $value['team'];

    if (array_key_exists($key, $list)) {
        $list[$key]['team_points'] += $value['team_points'];
        $list[$key]['team_occurrences'] ++;
    } else {
        $list[$key] = $value;
        $list[$key]['team_occurrences'] = 1;
    }
}
usort($list ,function($a, $b){ $a = $a['team_points'] ; $b = $b['team_points'] ; return ($a == $b) ? 0 : (($a < $b) ? 1 : -1 ) ;});

?>

But on the server it throws an error:

Parse error: syntax error, unexpected T_FUNCTION, expecting ')'

for this line:

array_map(function($var){}, $matches_array_1);

My localhost WAMP PHP version is 5.4.3

My server PHP version is 5.2.17

I would like to change th code so it works on both environments.

Thanks for any advice.

Upvotes: 1

Views: 395

Answers (1)

Musa
Musa

Reputation: 97672

Anonymous functions are available from PHP 5.3.0. See http://php.net/manual/en/functions.anonymous.php

Upvotes: 8

Related Questions