3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['page' => '32', 'position' => 'append', 'priority' => '1'], ['page' => '32', 'position' => 'append', 'priority' => '2'], ['page' => '32', 'position' => 'prepend', 'priority' => '3'], ['page' => '32', 'position' => 'both', 'priority' => '3'], ['page' => '32', 'position' => 'prepend', 'priority' => '4'], ['page' => '143', 'position' => 'prepend', 'priority' => '18'], ['page' => '143', 'position' => 'append', 'priority' => '18'], ['page' => '143', 'position' => 'prepend', 'priority' => '19'], ]; $result = []; foreach ($array as $row) { if (!isset($result[$row['page']])) { $result[$row['page']] = ['both' => [], 'non-both' => []]; } if ($row['position'] !== 'both') { if ($result[$row['page']]['both']) { continue; // nothing worth doing in this case, ignore the row } else { $result[$row['page']]['non-both'][] = $row; } } else { $result[$row['page']]['both'][] = $row; } } foreach ($result as $page => $rows) { $keep = []; foreach ($rows['both'] ?: $rows['non-both'] as $row) { if (!$keep || $row['priority'] < $keep[0]['priority']) { $keep = [$row]; } elseif ($row['priority'] === $keep[0]['priority']) { $keep[] = $row; } } if ($keep[0]['position'] !== 'both') { rsort($keep); } $result[$page] = $keep; } var_export($result);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 32 => array ( 0 => array ( 'page' => '32', 'position' => 'both', 'priority' => '3', ), ), 143 => array ( 0 => array ( 'page' => '143', 'position' => 'prepend', 'priority' => '18', ), 1 => array ( 'page' => '143', 'position' => 'append', 'priority' => '18', ), ), )

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:
158.31 ms | 406 KiB | 5 Q