3v4l.org

run code in 300+ PHP versions simultaneously
<?php $stops = Array ( 0 => Array ( 'agency_stop_id' => 1, 'routes' => Array ( '_ids' => Array (0 => 'Route 1', 1 => 'Route 2' ))), 1 => Array ( 'agency_stop_id' => 5, 'routes' => Array ( '_ids' => Array (0 => 'Route 1', 1 => 'Route 2' ))), 2 => Array ( 'agency_stop_id' => 5, 'routes' => Array ( '_ids' => Array (0 => 'Route 3', 1 => 'Route 4' ))), ); $out = []; $stops = array_unique($stops, SORT_REGULAR); $stopids = array_unique(array_column($stops, 'agency_stop_id')); foreach ($stopids as $stopid) { $keys = array_keys(array_column($stops, 'agency_stop_id'), $stopid); //Create an array of the matching stops foreach ($keys as $key) { $stop = array_map( function ($k) use ($stops) { return $stops[$k]; }, $key ); } //print_r($stop); //if there is only one if (count($stop) == 1) { //save array to $out $out[] = $stop[0]; //if there is more then one } elseif (count($keys) > 1) { $stop = array_merge_recursive($stop[0], [ 'routes' => $stop[1]['routes']]); $out[] = $stop; } } print_r($out); #print_r($new_array[0]); #print_r(Array( 'routes' => $new_array[1]['routes']));
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, int given in /in/iMRhr:17 Stack trace: #0 /in/iMRhr(17): array_map(Object(Closure), 0) #1 {main} thrown in /in/iMRhr on line 17
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
171.49 ms | 405 KiB | 5 Q