3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_transpose(array|object $object_or_array): array|object { $levelOneType = gettype($object_or_array); if (!in_array($levelOneType, ['array', 'object'])) { throw new Exception("Error: array_transpose() expects parameter 1 to be an array or object, $levelOneType given"); } $result = []; foreach ($object_or_array as $rowKey => $row) { $levelTwoType = gettype($row); if (!in_array($levelTwoType, ['array', 'object'])) { throw new Exception("Error: array_transpose() expects parameter 1 to contain rows of arrays or objects, $levelTwoType given"); } foreach ($row as $columnKey => $value) { $result[$columnKey][$rowKey] = $value; } } return $result; } $names = ['Anne', 'Burt', 'Chad', 'Dawn']; $ages = [18, 22, 20, 21]; $pets = ['dog', 'cat', 'fish', 'bird']; var_export(array_transpose(compact(['names', 'ages', 'pets'])));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jOQte
function name:  (null)
number of ops:  13
compiled vars:  !0 = $names, !1 = $ages, !2 = $pets
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     1        ASSIGN                                                   !1, <array>
   23     2        ASSIGN                                                   !2, <array>
   25     3        INIT_FCALL                                               'var_export'
          4        INIT_FCALL                                               'array_transpose'
          5        INIT_FCALL                                               'compact'
          6        SEND_VAL                                                 <array>
          7        DO_ICALL                                         $6      
          8        SEND_VAR                                                 $6
          9        DO_FCALL                                      0  $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function array_transpose:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
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
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 36
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/jOQte
function name:  array_transpose
number of ops:  43
compiled vars:  !0 = $object_or_array, !1 = $levelOneType, !2 = $result, !3 = $row, !4 = $rowKey, !5 = $levelTwoType, !6 = $value, !7 = $columnKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        GET_TYPE                                         ~8      !0
          2        ASSIGN                                                   !1, ~8
    5     3        IN_ARRAY                                         ~10     !1, <array>
          4        BOOL_NOT                                         ~11     ~10
          5      > JMPZ                                                     ~11, ->13
    6     6    >   NEW                                              $12     'Exception'
          7        ROPE_INIT                                     3  ~14     'Error%3A+array_transpose%28%29+expects+parameter+1+to+be+an+array+or+object%2C+'
          8        ROPE_ADD                                      1  ~14     ~14, !1
          9        ROPE_END                                      2  ~13     ~14, '+given'
         10        SEND_VAL_EX                                              ~13
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $12
    8    13    >   ASSIGN                                                   !2, <array>
    9    14      > FE_RESET_R                                       $18     !0, ->38
         15    > > FE_FETCH_R                                       ~19     $18, !3, ->38
         16    >   ASSIGN                                                   !4, ~19
   10    17        GET_TYPE                                         ~21     !3
         18        ASSIGN                                                   !5, ~21
   11    19        IN_ARRAY                                         ~23     !5, <array>
         20        BOOL_NOT                                         ~24     ~23
         21      > JMPZ                                                     ~24, ->29
   12    22    >   NEW                                              $25     'Exception'
         23        ROPE_INIT                                     3  ~27     'Error%3A+array_transpose%28%29+expects+parameter+1+to+contain+rows+of+arrays+or+objects%2C+'
         24        ROPE_ADD                                      1  ~27     ~27, !5
         25        ROPE_END                                      2  ~26     ~27, '+given'
         26        SEND_VAL_EX                                              ~26
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $25
   14    29    > > FE_RESET_R                                       $30     !3, ->36
         30    > > FE_FETCH_R                                       ~31     $30, !6, ->36
         31    >   ASSIGN                                                   !7, ~31
   15    32        FETCH_DIM_W                                      $33     !2, !7
         33        ASSIGN_DIM                                               $33, !4
         34        OP_DATA                                                  !6
   14    35      > JMP                                                      ->30
         36    >   FE_FREE                                                  $30
    9    37      > JMP                                                      ->15
         38    >   FE_FREE                                                  $18
   18    39        VERIFY_RETURN_TYPE                                       !2
         40      > RETURN                                                   !2
   19    41*       VERIFY_RETURN_TYPE                                       
         42*     > RETURN                                                   null

End of function array_transpose

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.62 ms | 1010 KiB | 16 Q