3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 'NUM' => [ 101, 102, 103, ], 'NOM' => [ 'Smith', 'Robson', 'Daniels', ], 'PRENOM' => [ 'Alice', 'Bob', 'Charlie', ], ]; // Grab all possible outer keys $outerKeys = array_keys($data); // Make sure all child arrays are the same size $innerCount = null; foreach($outerKeys as $key) { // Also make sure that we've got a list so that we don't have to keep // track of child keys. For a 7.x polyfill see // https://www.php.net/manual/en/function.array-is-list.php if(!array_is_list($data[$key])){ throw new RuntimeException('Child array is not a list'); } // Count the first item if(null === $innerCount){ $innerCount = count($data[$key]); continue; } // Compare the known count with the current child array if($innerCount !== count($data[$key])){ throw new RuntimeException('Child array does not have equal item count'); } } $lines = []; for($idx = 0; $idx < $innerCount; $idx++){ $buf = []; foreach($outerKeys as $key){ $buf[] = $key . ':' . $data[$key][$idx]; } $lines[] = implode(' ', $buf); } echo implode(PHP_EOL, $lines);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 33
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 37
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 47
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 47
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 37
Branch analysis from position: 57
Branch analysis from position: 37
Branch analysis from position: 47
Branch analysis from position: 33
filename:       /in/XZbgL
function name:  (null)
number of ops:  63
compiled vars:  !0 = $data, !1 = $outerKeys, !2 = $innerCount, !3 = $key, !4 = $lines, !5 = $idx, !6 = $buf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'array_keys'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
   25     5        ASSIGN                                                   !2, null
   26     6      > FE_RESET_R                                       $11     !1, ->33
          7    > > FE_FETCH_R                                               $11, !3, ->33
   31     8    >   INIT_FCALL                                               'array_is_list'
          9        FETCH_DIM_R                                      ~12     !0, !3
         10        SEND_VAL                                                 ~12
         11        DO_ICALL                                         $13     
         12        BOOL_NOT                                         ~14     $13
         13      > JMPZ                                                     ~14, ->18
   32    14    >   NEW                                              $15     'RuntimeException'
         15        SEND_VAL_EX                                              'Child+array+is+not+a+list'
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $15
   36    18    >   TYPE_CHECK                                    2          !2
         19      > JMPZ                                                     ~17, ->24
   37    20    >   FETCH_DIM_R                                      ~18     !0, !3
         21        COUNT                                            ~19     ~18
         22        ASSIGN                                                   !2, ~19
   38    23      > JMP                                                      ->7
   42    24    >   FETCH_DIM_R                                      ~21     !0, !3
         25        COUNT                                            ~22     ~21
         26        IS_NOT_IDENTICAL                                         !2, ~22
         27      > JMPZ                                                     ~23, ->32
   43    28    >   NEW                                              $24     'RuntimeException'
         29        SEND_VAL_EX                                              'Child+array+does+not+have+equal+item+count'
         30        DO_FCALL                                      0          
         31      > THROW                                         0          $24
   26    32    > > JMP                                                      ->7
         33    >   FE_FREE                                                  $11
   47    34        ASSIGN                                                   !4, <array>
   48    35        ASSIGN                                                   !5, 0
         36      > JMP                                                      ->55
   49    37    >   ASSIGN                                                   !6, <array>
   50    38      > FE_RESET_R                                       $29     !1, ->47
         39    > > FE_FETCH_R                                               $29, !3, ->47
   51    40    >   CONCAT                                           ~31     !3, '%3A'
         41        FETCH_DIM_R                                      ~32     !0, !3
         42        FETCH_DIM_R                                      ~33     ~32, !5
         43        CONCAT                                           ~34     ~31, ~33
         44        ASSIGN_DIM                                               !6
         45        OP_DATA                                                  ~34
   50    46      > JMP                                                      ->39
         47    >   FE_FREE                                                  $29
   53    48        INIT_FCALL                                               'implode'
         49        SEND_VAL                                                 '+'
         50        SEND_VAR                                                 !6
         51        DO_ICALL                                         $36     
         52        ASSIGN_DIM                                               !4
         53        OP_DATA                                                  $36
   48    54        PRE_INC                                                  !5
         55    >   IS_SMALLER                                               !5, !2
         56      > JMPNZ                                                    ~38, ->37
   56    57    >   INIT_FCALL                                               'implode'
         58        SEND_VAL                                                 '%0A'
         59        SEND_VAR                                                 !4
         60        DO_ICALL                                         $39     
         61        ECHO                                                     $39
         62      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.84 ms | 1009 KiB | 16 Q