3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = [ ['item1' => 'a', 'item2' => 'c', 'item3' => 'd2', 'item4' => 'f'], ['item1' => 'a', 'item2' => 'c', 'item3' => 'd2', 'item4' => 'g'], ['item1' => 'a', 'item2' => 'd', 'item3' => 'd3', 'item4' => 'h'], ['item1' => 'a', 'item2' => 'd', 'item3' => 'e', 'item4' => 'i'], ['item1' => 'b', 'item2' => 'c', 'item3' => 'e', 'item4' => 'j'], ['item1' => 'b', 'item2' => 'c', 'item3' => 'e', 'item4' => 'k'] ]; $result = []; foreach ($items as $row) { $k1 = $row['item1']; $k2 = $row['item1'] . '_' . $row['item2']; $k3 = $row['item1'] . '_' . $row['item2'] . '_' . $row['item3']; if (!isset($ref3[$k3])) { $ref3[$k3] = [$row['item3'], [$row['item4']]]; if (!isset($ref2[$k2])) { $ref2[$k2] = [$row['item2'], &$ref3[$k3]]; if (!isset($ref1[$k1])) { $ref1[$k1] = [$row['item1'], &$ref2[$k2]]; $result[] = &$ref1[$k1]; } else { $ref1[$k1][] = &$ref2[$k2]; } } else { $ref2[$k2][1][] = &$ref3[$k3]; } } else { $ref3[$k3][1][] = $row['item4']; } } echo json_encode($result);
Output for git.master, git.master_jit, rfc.property-hooks
[["a",["c",["d2",["f","g"]]],["d",["d3",["h"],["e",["i"]]]]],["b",["c",["e",["j","k"]]]]]

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:
66.74 ms | 405 KiB | 5 Q