Anonymous function in array_walk is throwing error on PHP 5.2

56 Views Asked by At

Below is array_walk function which is throwing error on php 5.2. I have 5.2 version on stage and 5.3 on local and dev. Code works fine on local and dev php version.

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

There are 1 best solutions below

0
Kalashir On

I have solved the issue by doing below code.

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));