3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = array ( 'expanded' => 1, 'key' => 'root_1', 'title' => 'root', 'children' => array ( 0 => array ( 'folder' => 1, 'key' => 34, 'title' => 'YAY PROJECTS' ), 1 => array ( 'expanded' => 1, 'folder' => 1, 'key' => 6, 'title' => 'Grand Designs Episodes', 'children' => array ( 0 => array ( 'folder' => 1, 'key' => 8, 'title' => 'AU Episodes' ), 1 => array ( 'expanded' => 1, 'folder' => 1, 'key' => 7, 'title' => 'UK Episodes', 'children' => array ( 0 => array ( 'key' => 9, 'title' => 'Start something' ), 1 => array ( 'key' => 2, 'title' => 'Grand Designs Season 10' ), ), ) ) ), 2 => array ( 'expanded' => 1, 'folder' => 1, 'key' => 5, 'title' => 'Animations', 'children' => array ( 0 => array ( 'key' => 4, 'title' => 'Futurama Episode 191' ), 1 => array ( 'key' => 3, 'title' => 'Miniscule Series 5 Ep1' ), 2 => array ( 'key' => 1, 'title' => 'The Simpsons Episode 459' ) ) ), 3 => array ( 'folder' => 1, 'key' => 11, 'title' => 'Test Folder' ), 4 => array ( 'folder' => 1, 'key' => 10, 'title' => 'Testing' ) ) ); function generateParentIds(&$input, $parentId = 0) { $input['parent_id'] = $parentId; if (isset($input['children'])) { foreach ($input['children'] as &$child) { generateParentIds($child, $input['key']); } } } generateParentIds($input); print_r($input);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Array ( [expanded] => 1 [key] => root_1 [title] => root [children] => Array ( [0] => Array ( [folder] => 1 [key] => 34 [title] => YAY PROJECTS [parent_id] => root_1 ) [1] => Array ( [expanded] => 1 [folder] => 1 [key] => 6 [title] => Grand Designs Episodes [children] => Array ( [0] => Array ( [folder] => 1 [key] => 8 [title] => AU Episodes [parent_id] => 6 ) [1] => Array ( [expanded] => 1 [folder] => 1 [key] => 7 [title] => UK Episodes [children] => Array ( [0] => Array ( [key] => 9 [title] => Start something [parent_id] => 7 ) [1] => Array ( [key] => 2 [title] => Grand Designs Season 10 [parent_id] => 7 ) ) [parent_id] => 6 ) ) [parent_id] => root_1 ) [2] => Array ( [expanded] => 1 [folder] => 1 [key] => 5 [title] => Animations [children] => Array ( [0] => Array ( [key] => 4 [title] => Futurama Episode 191 [parent_id] => 5 ) [1] => Array ( [key] => 3 [title] => Miniscule Series 5 Ep1 [parent_id] => 5 ) [2] => Array ( [key] => 1 [title] => The Simpsons Episode 459 [parent_id] => 5 ) ) [parent_id] => root_1 ) [3] => Array ( [folder] => 1 [key] => 11 [title] => Test Folder [parent_id] => root_1 ) [4] => Array ( [folder] => 1 [key] => 10 [title] => Testing [parent_id] => root_1 ) ) [parent_id] => 0 )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [expanded] => 1 [key] => root_1 [title] => root [children] => Array ( [0] => Array ( [folder] => 1 [key] => 34 [title] => YAY PROJECTS [parent_id] => root_1 ) [1] => Array ( [expanded] => 1 [folder] => 1 [key] => 6 [title] => Grand Designs Episodes [children] => Array ( [0] => Array ( [folder] => 1 [key] => 8 [title] => AU Episodes [parent_id] => 6 ) [1] => Array ( [expanded] => 1 [folder] => 1 [key] => 7 [title] => UK Episodes [children] => Array ( [0] => Array ( [key] => 9 [title] => Start something [parent_id] => 7 ) [1] => Array ( [key] => 2 [title] => Grand Designs Season 10 [parent_id] => 7 ) ) [parent_id] => 6 ) ) [parent_id] => root_1 ) [2] => Array ( [expanded] => 1 [folder] => 1 [key] => 5 [title] => Animations [children] => Array ( [0] => Array ( [key] => 4 [title] => Futurama Episode 191 [parent_id] => 5 ) [1] => Array ( [key] => 3 [title] => Miniscule Series 5 Ep1 [parent_id] => 5 ) [2] => Array ( [key] => 1 [title] => The Simpsons Episode 459 [parent_id] => 5 ) ) [parent_id] => root_1 ) [3] => Array ( [folder] => 1 [key] => 11 [title] => Test Folder [parent_id] => root_1 ) [4] => Array ( [folder] => 1 [key] => 10 [title] => Testing [parent_id] => root_1 ) ) [parent_id] => 0 )

preferences:
224.53 ms | 413 KiB | 181 Q