3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ "id" => "127", "title" => "Apple", "deleted" => "0", "parent" => NULL, "usp_id" => "445", "user_id" => NULL, ], [ "id" => "159", "title" => "Renault Duster", "deleted" => "0", "parent" => NULL, "usp_id" => "495", "user_id" => NULL, ], [ "id" => "7", "title" => "Services", "deleted" => "0", "parent" => "127", "usp_id" => "79", "user_id" => "275", ], ]; foreach ($arr as $key0 => $record) { if (null !== $record['parent']) { foreach ($arr as $key1 => $parent) { if ($parent['id'] === $record['parent']) { $arr[$key1]['children'][] = $record; // push child into parent['sub'] unset($arr[$key0]); // delete child } } } } print_r($arr);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [id] => 127 [title] => Apple [deleted] => 0 [parent] => [usp_id] => 445 [user_id] => [children] => Array ( [0] => Array ( [id] => 7 [title] => Services [deleted] => 0 [parent] => 127 [usp_id] => 79 [user_id] => 275 ) ) ) [1] => Array ( [id] => 159 [title] => Renault Duster [deleted] => 0 [parent] => [usp_id] => 495 [user_id] => ) )

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