3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createArrayMap(iterable $input, string $indexKey, ?string $valueKey = null): array { $map = []; foreach ($input as $obj) { $arr = $obj; $mapKey = $arr[$indexKey]; $value = $valueKey !== null ? $arr[$valueKey] : $obj; if (!array_key_exists($mapKey, $map)) { $map[$mapKey] = []; } $map[$mapKey][] = $value; } return $map; } $data = [ [ 'key' => 'first', 'name' => 'Foo' ], [ 'key' => 'second', 'name' => 'Bar' ], null ]; var_dump(createArrayMap($data, 'key'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bRhDB
function name:  (null)
number of ops:  9
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   35     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'createarraymap'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'key'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function createarraymap:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 25
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 25
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
Branch analysis from position: 21
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/bRhDB
function name:  createArrayMap
number of ops:  30
compiled vars:  !0 = $input, !1 = $indexKey, !2 = $valueKey, !3 = $map, !4 = $obj, !5 = $arr, !6 = $mapKey, !7 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    5     3        ASSIGN                                                   !3, <array>
    7     4      > FE_RESET_R                                       $9      !0, ->25
          5    > > FE_FETCH_R                                               $9, !4, ->25
    8     6    >   ASSIGN                                                   !5, !4
   10     7        FETCH_DIM_R                                      ~11     !5, !1
          8        ASSIGN                                                   !6, ~11
   11     9        TYPE_CHECK                                  1020          !2
         10      > JMPZ                                                     ~13, ->14
         11    >   FETCH_DIM_R                                      ~14     !5, !2
         12        QM_ASSIGN                                        ~15     ~14
         13      > JMP                                                      ->15
         14    >   QM_ASSIGN                                        ~15     !4
         15    >   ASSIGN                                                   !7, ~15
   13    16        ARRAY_KEY_EXISTS                                 ~17     !6, !3
         17        BOOL_NOT                                         ~18     ~17
         18      > JMPZ                                                     ~18, ->21
   14    19    >   ASSIGN_DIM                                               !3, !6
         20        OP_DATA                                                  <array>
   17    21    >   FETCH_DIM_W                                      $20     !3, !6
         22        ASSIGN_DIM                                               $20
         23        OP_DATA                                                  !7
    7    24      > JMP                                                      ->5
         25    >   FE_FREE                                                  $9
   20    26        VERIFY_RETURN_TYPE                                       !3
         27      > RETURN                                                   !3
   21    28*       VERIFY_RETURN_TYPE                                       
         29*     > RETURN                                                   null

End of function createarraymap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.85 ms | 1403 KiB | 16 Q