3v4l.org

run code in 300+ PHP versions simultaneously
<?php function zip(...$arr){ $newArr = []; $count_max = 0; foreach($arr as $a) { $newArr[] = array_reverse($a); $count_max = count($a) > $count_max ? count($a) : $count_max; } while($count_max) { $return = []; foreach($newArr as &$a) $return[] = array_pop($a); yield $return; $count_max--; }; } $i = ['a', 'b', 'c', 'd']; $j = ['1', '2', '3', '4']; $g = ['!', '@', '#', '$']; $c = 0; foreach(zip($i, $j, $g) as [$k, $l, $m]) { $c++; printf("%s-%d-%s - Count: %d\n", $k, $l, $m, $c); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 27
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/9aqpl
function name:  (null)
number of ops:  29
compiled vars:  !0 = $i, !1 = $j, !2 = $g, !3 = $c, !4 = $k, !5 = $l, !6 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   24     1        ASSIGN                                                   !1, <array>
   25     2        ASSIGN                                                   !2, <array>
   27     3        ASSIGN                                                   !3, 0
   28     4        INIT_FCALL                                               'zip'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !2
          8        DO_FCALL                                      0  $11     
          9      > FE_RESET_R                                       $12     $11, ->27
         10    > > FE_FETCH_R                                               $12, $13, ->27
         11    >   FETCH_LIST_R                                     $14     $13, 0
         12        ASSIGN                                                   !4, $14
         13        FETCH_LIST_R                                     $16     $13, 1
         14        ASSIGN                                                   !5, $16
         15        FETCH_LIST_R                                     $18     $13, 2
         16        ASSIGN                                                   !6, $18
         17        FREE                                                     $13
   29    18        PRE_INC                                                  !3
   30    19        INIT_FCALL                                               'printf'
         20        SEND_VAL                                                 '%25s-%25d-%25s+-+Count%3A+%25d%0A'
         21        SEND_VAR                                                 !4
         22        SEND_VAR                                                 !5
         23        SEND_VAR                                                 !6
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                                 
   28    26      > JMP                                                      ->10
         27    >   FE_FREE                                                  $12
   31    28      > RETURN                                                   1

Function zip:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 22
Branch analysis from position: 35
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 125) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
2 jumps found. (Code = 126) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 22
Branch analysis from position: 35
Branch analysis from position: 22
Branch analysis from position: 31
Branch analysis from position: 20
filename:       /in/9aqpl
function name:  zip
number of ops:  36
compiled vars:  !0 = $arr, !1 = $newArr, !2 = $count_max, !3 = $a, !4 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_VARIADIC                                    !0      
          1        GENERATOR_CREATE                                         
    4     2        ASSIGN                                                   !1, <array>
    6     3        ASSIGN                                                   !2, 0
    7     4      > FE_RESET_R                                       $7      !0, ->20
          5    > > FE_FETCH_R                                               $7, !3, ->20
    8     6    >   INIT_FCALL                                               'array_reverse'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $9      
          9        ASSIGN_DIM                                               !1
         10        OP_DATA                                                  $9
    9    11        COUNT                                            ~10     !3
         12        IS_SMALLER                                               !2, ~10
         13      > JMPZ                                                     ~11, ->17
         14    >   COUNT                                            ~12     !3
         15        QM_ASSIGN                                        ~13     ~12
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~13     !2
         18    >   ASSIGN                                                   !2, ~13
    7    19      > JMP                                                      ->5
         20    >   FE_FREE                                                  $7
   12    21      > JMP                                                      ->34
   13    22    >   ASSIGN                                                   !4, <array>
   15    23      > FE_RESET_RW                                      $16     !1, ->31
         24    > > FE_FETCH_RW                                              $16, !3, ->31
   16    25    >   INIT_FCALL                                               'array_pop'
         26        SEND_REF                                                 !3
         27        DO_ICALL                                         $18     
         28        ASSIGN_DIM                                               !4
         29        OP_DATA                                                  $18
   15    30      > JMP                                                      ->24
         31    >   FE_FREE                                                  $16
   18    32        YIELD                                                    !4
   19    33        PRE_DEC                                                  !2
   12    34    > > JMPNZ                                                    !2, ->22
   21    35    > > GENERATOR_RETURN                                         

End of function zip

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
199.4 ms | 1403 KiB | 20 Q