3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ [ '1@02@43@170@1', '1@02@43@176@1', '1@02@43@182@1', '1@02@42@182@1', '1@02@42@176@1', ], [ '1@02@43@170@1', '1@02@43@176@1', '1@02@43@182@1', '1@02@42@182@1', '1@02@42@176@1', '1@03@43@170@1', '1@03@43@176@1', '1@03@43@182@1', '1@03@42@182@1', '1@03@42@176@1', ], [ '1@02@43@170@1', '1@02@43@170@1', ] ]; function killYourParentIfYouHaveOne($level) { if (count($level) === 1) { $key = key($level); $level = is_array($level[$key]) ? killYourParentIfYouHaveOne($level[$key]) : []; } return $level; } function differingTree(array $array): array { $result = []; foreach ($array as $item) { [$a, $b, $c, $d, $e] = explode('@', $item, 5); $result[$a][$b][$c][$d] = $e; } return killYourParentIfYouHaveOne($result); } foreach ($tests as $test) { echo var_export(differingTree($test), true) . "\n---\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
array ( 43 => array ( 170 => '1', 176 => '1', 182 => '1', ), 42 => array ( 182 => '1', 176 => '1', ), ) --- array ( '02' => array ( 43 => array ( 170 => '1', 176 => '1', 182 => '1', ), 42 => array ( 182 => '1', 176 => '1', ), ), '03' => array ( 43 => array ( 170 => '1', 176 => '1', 182 => '1', ), 42 => array ( 182 => '1', 176 => '1', ), ), ) --- array ( ) ---

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:
160.91 ms | 407 KiB | 5 Q