3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on OHq93
Output for 7.0.0 - 7.2.0
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.6.28
Fatal error: Cannot unset string offsets in /in/4LdKf on line 118
Process exited with code 255.
Output for 5.3.17 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/4LdKf on line 2
Process exited with code 255.