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 ($v) { return $v['label']; }, $input ); 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/5WLj8
function name:  (null)
number of ops:  23
compiled vars:  !0 = $array, !1 = $translations, !2 = $input, !3 = $newArray, !4 = $value, !5 = $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%2F5WLj8%3A16%240'
   18     3        SEND_VAL                                                 ~7
   19     4        SEND_VAR                                                 !2
          5        DO_ICALL                                         $8      
   15     6        ASSIGN                                                   !1, $8
   22     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   41    10        ASSIGN                                                   !3, <array>
   42    11      > FE_RESET_R                                       $12     !0, ->18
         12    > > FE_FETCH_R                                       ~13     $12, !4, ->18
         13    >   ASSIGN                                                   !5, ~13
   43    14        FETCH_DIM_R                                      ~16     !4, 'label'
         15        ASSIGN_DIM                                               !3, !5
         16        OP_DATA                                                  ~16
   42    17      > JMP                                                      ->12
         18    >   FE_FREE                                                  $12
   46    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.65 ms | 1396 KiB | 17 Q