3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['App', 'Classes', 'Auth'], ['App', 'Classes', 'Auth'], ['App', 'Classes', 'Middleware'], ['App', 'Classes', 'Phone'], ['App', 'Classes', 'Auth'], ['App', 'Mail'], ['App', 'Mail', 'Sender'], ['App', 'Box'], ]; $results = json_decode(json_encode($array)); $tree = null; foreach ($results as $result) { $thisref = &$refs->{$result[0]}; $tree->{$result[0]} = &$thisref; $thisref = &$refs->{$result[1]}; $tree->{$result[0]}->{$result[1]} = &$thisref; if (!empty($result[2])) { $thisref = &$refs->{$result[2]}; $refs->{$result[0]}->{$result[1]}[] = $result[2];//&$thisref; $refs->{$result[0]}->{$result[1]} = array_unique($refs->{$result[0]}->{$result[1]}); } } print_r(json_decode(json_encode($tree), true));
based on 1ZcC1
Output for 8.0.0 - 8.0.3
Fatal error: Uncaught Error: Attempt to modify property "App" on null in /in/2udcX:15 Stack trace: #0 {main} thrown in /in/2udcX on line 15
Process exited with code 255.
Output for 7.4.0 - 7.4.16
Warning: Creating default object from empty value in /in/2udcX on line 15 Warning: Creating default object from empty value in /in/2udcX on line 16 Warning: Creating default object from empty value in /in/2udcX on line 18 Array ( [App] => Array ( [Classes] => Array ( [0] => Auth [1] => Middleware [2] => Phone ) [Mail] => Array ( [0] => Sender ) [Box] => ) )
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.26
Array ( [App] => Array ( [Classes] => Array ( [0] => Auth [1] => Middleware [2] => Phone ) [Mail] => Array ( [0] => Sender ) [Box] => ) )
Output for 7.1.25 - 7.1.33
Array ( [App] => Array ( [Classes] => Array ( [0] => Auth [2] => Middleware [3] => Phone ) [Mail] => Array ( [0] => Sender ) [Box] => ) )