array_walk中的匿名函数在PHP 5.2上引发错误

时间:2018-12-03 06:33:50

标签: php php-5.3 php-5.2

下面是array_walk函数,该函数在php 5.2上引发错误。 我在舞台上有5.2版,在本地和开发版上有5.3版。代码可以在本地和开发php版本上正常工作。

foreach($favTracks as $track_id) {
array_walk($tracks, function ($t, $k) use ($track_id, &$return) {    
    if($t['track_code'] == $track_id) {
        $trackDetails = variable_get('drf_admin_top_track_'. $k . '_news_list', array());
        $return[$track_id]  = array('articles' => 
        get_fav_details($trackDetails), 
        'trackName' => isset($t['title']) ? $t['title'] : "" );
    }        
});    
}

1 个答案:

答案 0 :(得分:0)

我通过执行以下代码解决了该问题。

function getTopTrackWalk($t, $k, $trackArr) {    
  if($t['track_code'] == $trackArr[0]) {
  $trackDetails = variable_get('drf_admin_top_track_'. $k . '_news_list', array());
  $trackArr[1][$trackArr[0]]  = array('articles' => 
  get_fav_details($trackDetails), 
'trackName' => isset($t['title']) ? $t['title'] : "" );
}           
}
array_walk($tracks, "getTopTrackWalk", array($track_id, &$return));