3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = [ 1 => [ [ 'key' => 'fe', 'name' => 'En plantilla a dedicación completa', 'dedication' => 2, 'relationship' =>2 ], [ 'key' => 'ff', 'name' => 'Freelance a dedicación completa', 'dedication' => 2, 'relationship' => 2 ], ], 2 => [ [ 'name' => 'En Plantilla', 'childs' => [ [ 'key' => 'pem', 'name' => 'Mañanas', 'dedication' => 1, 'relationship' => 2, 'shiftPreference' => 3 ], [ 'key' => 'pea', 'name' => 'Tardes', 'dedication' => 1, 'relationship' => 2, 'shiftPreference' => 3 ], [ 'key' => 'ped', 'name' => 'Indistinto', 'dedication' => 4, 'relationship' => 5, 'shiftPreference' => 1 ], ], ], [ 'name' => 'Freelance', 'childs' => [ [ 'name' => 'Mañanas', 'childs' => [ [ 'key' => 'pfmm', 'name' => 'Más de 3 horas/día', 'dedication' => 1, 'relationship' => 2, 'shiftPreference' => 3, 'hoursOfService' => 5 ], [ 'key' => 'pfml', 'name' => 'Menos de 3 horas/día', 'parent' => 8, 'dedication' => 2, 'relationship' => 5, 'shiftPreference' => 32, 'hoursOfService' => 32 ], ], ], [ 'name' => 'Tardes', 'childs' => [ [ 'key' => 'pfam', 'name' => 'Más de 3 horas/día', 'dedication' => 1, 'relationship' => 2, 'shiftPreference' => 6, 'hoursOfService' => 4 ], [ 'key' => 'pfal', 'name' => 'Menos de 3 horas/día', 'dedication' => 3, 'relationship' => 5, 'shiftPreference' => 3, 'hoursOfService' => 1 ], ], ], [ 'name' => 'Indistinto', 'childs' => [ [ 'key' => 'pfdm', 'name' => 'Más de 3 horas/día', 'dedication' => 21, 'relationship' => 6, 'shiftPreference' => 25, 'hoursOfService' => 2 ], [ 'key' => 'pfdl', 'name' => 'Menos de 3 horas/día', 'dedication' => 434, 'relationship' => 2245243, 'shiftPreference' => 543, 'hoursOfService' => 324 ], ], ], ], ], ], ]; $results = $a[1]; array_walk_recursive($results, function(&$a){ unset($a['dedication'], $a['relationship'], $a['shiftPreference'], $a['hoursOfService']); }); var_dump($results); var_dump($a);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Cannot unset string offsets in /in/4LdKf:118 Stack trace: #0 [internal function]: {closure}('fe', 'key') #1 /in/4LdKf(117): array_walk_recursive(Array, Object(Closure)) #2 {main} thrown in /in/4LdKf on line 118
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught Error: Cannot unset string offsets in /in/4LdKf:118 Stack trace: #0 [internal function]: {closure}('fe', 'key') #1 /in/4LdKf(119): array_walk_recursive(Array, Object(Closure)) #2 {main} thrown in /in/4LdKf on line 118
Process exited with code 255.
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Cannot unset string offsets in /in/4LdKf on line 118
Process exited with code 255.

preferences:
182.16 ms | 402 KiB | 226 Q