3v4l.org

run code in 300+ PHP versions simultaneously
<?php $old = array( 20 => array( 'name' => 'Heels', 'path' => '10/15/20', ), 15 => array( 'name' => 'Sandals', 'path' => '15', ), 10 => array( 'name' => 'Trainers', 'path' => '10', ), ); $result = []; $mapper = array_combine(array_keys($old), array_column($old, 'name')); foreach ($old as $key => $value) { $path = implode(' > ', array_map(function($x) use ($mapper) { return $mapper[(int)$x]; }, explode('/', $value['path']))); $result[$key] = ['value' => $key,'label' => $path]; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 38
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 38
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/VL42l
function name:  (null)
number of ops:  43
compiled vars:  !0 = $old, !1 = $result, !2 = $mapper, !3 = $value, !4 = $key, !5 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   21     1        ASSIGN                                                   !1, <array>
   22     2        INIT_FCALL                                               'array_combine'
          3        INIT_FCALL                                               'array_keys'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $8      
          6        SEND_VAR                                                 $8
          7        INIT_FCALL                                               'array_column'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 'name'
         10        DO_ICALL                                         $9      
         11        SEND_VAR                                                 $9
         12        DO_ICALL                                         $10     
         13        ASSIGN                                                   !2, $10
   23    14      > FE_RESET_R                                       $12     !0, ->38
         15    > > FE_FETCH_R                                       ~13     $12, !3, ->38
         16    >   ASSIGN                                                   !4, ~13
   24    17        INIT_FCALL                                               'implode'
         18        SEND_VAL                                                 '+%3E+'
         19        INIT_FCALL                                               'array_map'
         20        DECLARE_LAMBDA_FUNCTION                          ~15     [0]
         21        BIND_LEXICAL                                             ~15, !2
   26    22        SEND_VAL                                                 ~15
         23        INIT_FCALL                                               'explode'
         24        SEND_VAL                                                 '%2F'
         25        FETCH_DIM_R                                      ~16     !3, 'path'
         26        SEND_VAL                                                 ~16
         27        DO_ICALL                                         $17     
         28        SEND_VAR                                                 $17
   24    29        DO_ICALL                                         $18     
   26    30        SEND_VAR                                                 $18
   24    31        DO_ICALL                                         $19     
         32        ASSIGN                                                   !5, $19
   28    33        INIT_ARRAY                                       ~22     !4, 'value'
         34        ADD_ARRAY_ELEMENT                                ~22     !5, 'label'
         35        ASSIGN_DIM                                               !1, !4
         36        OP_DATA                                                  ~22
   23    37      > JMP                                                      ->15
         38    >   FE_FREE                                                  $12
   31    39        INIT_FCALL                                               'print_r'
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                                 
         42      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VL42l
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $x, !1 = $mapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   25     2        CAST                                          4  ~2      !0
          3        FETCH_DIM_R                                      ~3      !1, ~2
          4      > RETURN                                                   ~3
   26     5*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.08 ms | 1022 KiB | 20 Q