3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'id_1_1' => 'id1', 'foo_1_2' => 'value1_1', 'bar_1_3' => 'value1_2', 'more_1_4' => 'value1_3', 'id_2_1' => 'id2', 'foo_2_2' => 'value2_1', 'bar_2_3' => 'value2_2', 'more_2_4' => 'value2_3' ]; function convert($a) { $map = [ ]; $result = []; foreach ($a as $array_key => $value) { list($newkey, $number) = explode('_', $array_key); if ($newkey === 'id') { $map[$number] = $value; $result[$value] = []; } elseif (key_exists($number, $map)) { $id = $map[$number]; $result[$id][$newkey] = $value; } } return $result; } $result = convert($array); var_export($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BrDGu
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   32     1        INIT_FCALL                                               'convert'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   33     5        INIT_FCALL                                               'var_export'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function convert:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 33
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 33
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 32
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/BrDGu
function name:  convert
number of ops:  36
compiled vars:  !0 = $a, !1 = $map, !2 = $result, !3 = $value, !4 = $array_key, !5 = $newkey, !6 = $number, !7 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, <array>
   19     3      > FE_RESET_R                                       $10     !0, ->33
          4    > > FE_FETCH_R                                       ~11     $10, !3, ->33
          5    >   ASSIGN                                                   !4, ~11
   20     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '_'
          8        SEND_VAR                                                 !4
          9        DO_ICALL                                         $13     
         10        FETCH_LIST_R                                     $14     $13, 0
         11        ASSIGN                                                   !5, $14
         12        FETCH_LIST_R                                     $16     $13, 1
         13        ASSIGN                                                   !6, $16
         14        FREE                                                     $13
   21    15        IS_IDENTICAL                                             !5, 'id'
         16      > JMPZ                                                     ~18, ->22
   22    17    >   ASSIGN_DIM                                               !1, !6
         18        OP_DATA                                                  !3
   23    19        ASSIGN_DIM                                               !2, !3
         20        OP_DATA                                                  <array>
         21      > JMP                                                      ->32
   24    22    >   INIT_FCALL                                               'key_exists'
         23        SEND_VAR                                                 !6
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $21     
         26      > JMPZ                                                     $21, ->32
   25    27    >   FETCH_DIM_R                                      ~22     !1, !6
         28        ASSIGN                                                   !7, ~22
   26    29        FETCH_DIM_W                                      $24     !2, !7
         30        ASSIGN_DIM                                               $24, !5
         31        OP_DATA                                                  !3
   19    32    > > JMP                                                      ->4
         33    >   FE_FREE                                                  $10
   29    34      > RETURN                                                   !2
   30    35*     > RETURN                                                   null

End of function convert

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
203.56 ms | 1406 KiB | 21 Q