I'm using AppServ 2.6.0 / Apache 2.2.8 / PHP 6.0.0-dev, and I'm getting an error with the following function.

<? if(count($ex) > 0) {
    foreach($ex as $k => $v) { 
      echo "<tr><td style='font-size:12px;'>".strip_tags($k)."</td>
      <td style='font-size:10px;'>".$v['count']."</td>
      <td style='font-size:10px;'>".implode(", ", array_map(function ($k, $v)
          { return $k."/".$v; }, array_keys($v['players']), array_values($v['players'])))."
      </td></tr>";  
    } 
 } ?>

The error is (Line 14 is where the array_map() is):

Parse error: syntax error, unexpected T_FUNCTION, expecting ')' ** on line 14

Sadly, I can't change the PHP version (I'm aware that the error might have to do with the PHP version). If I upgrade PHP, the whole project, that wasn't started by me, would fall apart.

Is there any way to get this code working on Apache 2.2.8 / PHP 6.0.0-dev?

If there isn't any way around this, and I'm forced to change my php version, is there any version out there that has PHP5.3 anonymous functions that also keeps the deprecated ones?

有帮助吗?

解决方案

Instead of using anonymous function you can define it as a "regular" function and pass its name to array_map:

function foo($k, $v) {
    return $k."/".$v;
}

array_map('foo', $my_array);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top