3v4l.org

run code in 500+ 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 = 35
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 35
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/VL42l
function name:  (null)
number of ops:  40
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, ->35
         15    > > FE_FETCH_R                                           ~13     $12, !3, ->35
         16    >   ASSIGN                                                       !4, ~13
   24    17        INIT_FCALL                                                   'array_map'
         18        DECLARE_LAMBDA_FUNCTION                              ~15     [0]
         19        BIND_LEXICAL                                                 ~15, !2
   26    20        SEND_VAL                                                     ~15
         21        INIT_FCALL                                                   'explode'
         22        SEND_VAL                                                     '%2F'
         23        FETCH_DIM_R                                          ~16     !3, 'path'
         24        SEND_VAL                                                     ~16
         25        DO_ICALL                                             $17     
         26        SEND_VAR                                                     $17
   24    27        DO_ICALL                                             $18     
         28        FRAMELESS_ICALL_2                implode             ~19     '+%3E+', $18
         29        ASSIGN                                                       !5, ~19
   28    30        INIT_ARRAY                                           ~22     !4, 'value'
         31        ADD_ARRAY_ELEMENT                                    ~22     !5, 'label'
         32        ASSIGN_DIM                                                   !1, !4
         33        OP_DATA                                                      ~22
   23    34      > JMP                                                          ->15
         35    >   FE_FREE                                                      $12
   31    36        INIT_FCALL                                                   'print_r'
         37        SEND_VAR                                                     !1
         38        DO_ICALL                                                     
         39      > 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:/in/VL42l:24}
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.5.0


preferences:
162.41 ms | 2188 KiB | 19 Q