3v4l.org

run code in 300+ PHP versions simultaneously
<?php $belongGroup = [ 2, 1 ]; $groups = [ 1 => ['parent_group_id' => 0, 'group_id' => 1], 2 => ['parent_group_id' => 1, 'group_id' => 2], 3 => ['parent_group_id' => 0, 'group_id' => 3], 4 => ['parent_group_id' => 0, 'group_id' => 4], ]; $result = []; foreach($belongGroup as $g) { $l = $groups[$g]; var_dump($l); while(true) { echo $l['parent_group_id'] == 0; if ($l['parent_group_id'] == 0) { break; } $parentId = $l['parent_group_id']; $l = $groups[$parentId]; unset($groups[$parentId]); } $result[] = intval($l['group_id']); } echo implode(", ", $result);
Output for 8.3.0 - 8.3.4, 8.3.6
array(2) { ["parent_group_id"]=> int(1) ["group_id"]=> int(2) } 1 Warning: Undefined array key 1 in /in/3nUVo on line 16 NULL Warning: Trying to access array offset on null in /in/3nUVo on line 19 1 Warning: Trying to access array offset on null in /in/3nUVo on line 20 Warning: Trying to access array offset on null in /in/3nUVo on line 27 1, 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(2) { ["parent_group_id"]=> int(1) ["group_id"]=> int(2) } 1 Warning: Undefined array key 1 in /in/3nUVo on line 16 NULL Warning: Trying to access array offset on null in /in/3nUVo on line 19 1 Warning: Trying to access array offset on null in /in/3nUVo on line 20 Warning: Trying to access array offset on null in /in/3nUVo on line 27 1, 0
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
array(2) { ["parent_group_id"]=> int(1) ["group_id"]=> int(2) } 1 Warning: Undefined array key 1 in /in/3nUVo on line 16 NULL Warning: Trying to access array offset on value of type null in /in/3nUVo on line 19 1 Warning: Trying to access array offset on value of type null in /in/3nUVo on line 20 Warning: Trying to access array offset on value of type null in /in/3nUVo on line 27 1, 0
Output for 7.4.0 - 7.4.33
array(2) { ["parent_group_id"]=> int(1) ["group_id"]=> int(2) } 1 Notice: Undefined offset: 1 in /in/3nUVo on line 16 NULL Notice: Trying to access array offset on value of type null in /in/3nUVo on line 19 1 Notice: Trying to access array offset on value of type null in /in/3nUVo on line 20 Notice: Trying to access array offset on value of type null in /in/3nUVo on line 27 1, 0
Output for 7.3.32 - 7.3.33
array(2) { ["parent_group_id"]=> int(1) ["group_id"]=> int(2) } 1NULL 11, 0
Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
array(2) { ["parent_group_id"]=> int(1) ["group_id"]=> int(2) } 1 Notice: Undefined offset: 1 in /in/3nUVo on line 16 NULL 11, 0

preferences:
219.15 ms | 403 KiB | 248 Q