why is arraymergerecursive not returning the output php?

It’s not working because that’s not how the function works. You need to write a custom function to achieve desired result.

function merge_result($data) 
{
   $result = [];
   $index = 0;
   $keys = [];
   foreach($data as $row) 
   {
       if(array_key_exists($row['id'], $keys)){
           $_index = $keys[$row['id']];
           $result[$_index]['stop'] = array_merge($result[$_index]['stop'], $row['stop']);
       }else {
           $keys[$row['id']] = $index; 
           $result[$index] = $row; 
          $index++;
       }

   }
  return $result;
}

$routes = merge_result(json_decode($data, true));

PS: Am unable to test because am on mobile phone.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top