3v4l.org

run code in 300+ PHP versions simultaneously
<?php $get_data = array( array( "MenuId" => "1", "MenuName" => "Perencanaan dan Pengadaan", "MenuParent" => "", "MenuLink" => "" ), array( "MenuId" => "1-1", "MenuName" => "RKA / DPA", "MenuParent" => "1", "MenuLink" => "" ), array( "MenuId" => "1-1-1", "MenuName" => "Daftar RKA / DPA", "MenuParent" => "1-1", "MenuLink" => "rkbu" ) ); function insert_into(&$array, array $keys, $value) { $last = array_pop($keys); foreach($keys as $key) { if(!array_key_exists($key, $array) || array_key_exists($key, $array) && !is_array($array[$key]['items'])) { $array[$key]['items'] = array(); } $array = &$array[$key]; } $array[$last] = $value; } $menuItems = array(); foreach($get_data as $item) { $levels = explode('-', $item['MenuId']); insert_into($menuItems, $levels, $item['MenuName']); } print_r($menuItems);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/qfm5q:29 Stack trace: #0 /in/qfm5q(41): insert_into(Array, Array, 'RKA / DPA') #1 {main} thrown in /in/qfm5q on line 29
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:
57.83 ms | 401 KiB | 8 Q