3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'de' => [ 'label' => 'German', 'id' => 912 ], 'cn' => [ 'label' => 'Chinese', 'id' => 913 ] ]; // Initial attempt $translations = array_map( function ($array) { unset($array['id']); return $array['label']; }, $array ); var_dump($translations); // Actual //[ // 0 => [ // 'de' => 'German' // ], // 1 => [ // 'cn' 'Chinese' // ] //] // Desired //[ // 'de' => 'German', // 'cn' => 'Chinese' //] // Works declaratively via the following... $newArray = []; foreach ($array as $key => $value) { $newArray[$key] = $value['label']; } var_dump($newArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/LHrtN
function name:  (null)
number of ops:  23
compiled vars:  !0 = $array, !1 = $translations, !2 = $newArray, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        INIT_FCALL                                               'array_map'
   16     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FLHrtN%3A16%240'
   19     3        SEND_VAL                                                 ~6
   20     4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
   15     6        ASSIGN                                                   !1, $7
   23     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   42    10        ASSIGN                                                   !2, <array>
   43    11      > FE_RESET_R                                       $11     !0, ->18
         12    > > FE_FETCH_R                                       ~12     $11, !3, ->18
         13    >   ASSIGN                                                   !4, ~12
   44    14        FETCH_DIM_R                                      ~15     !3, 'label'
         15        ASSIGN_DIM                                               !2, !4
         16        OP_DATA                                                  ~15
   43    17      > JMP                                                      ->12
         18    >   FE_FREE                                                  $11
   47    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FLHrtN%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LHrtN
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        UNSET_DIM                                                !0, 'id'
   18     2        FETCH_DIM_R                                      ~1      !0, 'label'
          3      > RETURN                                                   ~1
   19     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FLHrtN%3A16%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.2 ms | 1396 KiB | 17 Q