3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = Array ( 'cap' => 3, 'shirt' => 2, 'tatuaggio' => 1, 'badge' => 2 ); $res=[]; foreach($a as $k => $v){ $res[] = array_fill(0, $v, $k); } print_r(array_merge(...$res));// splat operator echo "----------------Without Splat operator -------------------------------------"; $res=[]; foreach($a as $k => $v){ $res = array_merge($res,array_fill(0, $v, $k)); } print_r($res); echo "----------------With foreach and for -------------------------------------"; $res=[]; foreach($a as $k => $v){ for($i=0;$i<$v;$i++) $res[] = $k; } print_r($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 37
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 37
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 54
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 54
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 48
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 48
Branch analysis from position: 53
Branch analysis from position: 48
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 37
Branch analysis from position: 13
filename:       /in/AJnfn
function name:  (null)
number of ops:  59
compiled vars:  !0 = $a, !1 = $res, !2 = $v, !3 = $k, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   10     2      > FE_RESET_R                                       $7      !0, ->13
          3    > > FE_FETCH_R                                       ~8      $7, !2, ->13
          4    >   ASSIGN                                                   !3, ~8
   11     5        INIT_FCALL                                               'array_fill'
          6        SEND_VAL                                                 0
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $11     
         10        ASSIGN_DIM                                               !1
         11        OP_DATA                                                  $11
   10    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $7
   13    14        INIT_FCALL                                               'print_r'
         15        INIT_FCALL                                               'array_merge'
         16        SEND_UNPACK                                              !1
         17        CHECK_UNDEF_ARGS                                         
         18        DO_ICALL                                         $12     
         19        SEND_VAR                                                 $12
         20        DO_ICALL                                                 
   14    21        ECHO                                                     '----------------Without+Splat+operator+-------------------------------------'
   15    22        ASSIGN                                                   !1, <array>
   16    23      > FE_RESET_R                                       $15     !0, ->37
         24    > > FE_FETCH_R                                       ~16     $15, !2, ->37
         25    >   ASSIGN                                                   !3, ~16
   17    26        INIT_FCALL                                               'array_merge'
         27        SEND_VAR                                                 !1
         28        INIT_FCALL                                               'array_fill'
         29        SEND_VAL                                                 0
         30        SEND_VAR                                                 !2
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                         $18     
         33        SEND_VAR                                                 $18
         34        DO_ICALL                                         $19     
         35        ASSIGN                                                   !1, $19
   16    36      > JMP                                                      ->24
         37    >   FE_FREE                                                  $15
   19    38        INIT_FCALL                                               'print_r'
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                                 
   20    41        ECHO                                                     '----------------With+foreach+and+for+-------------------------------------'
   21    42        ASSIGN                                                   !1, <array>
   22    43      > FE_RESET_R                                       $23     !0, ->54
         44    > > FE_FETCH_R                                       ~24     $23, !2, ->54
         45    >   ASSIGN                                                   !3, ~24
   23    46        ASSIGN                                                   !4, 0
         47      > JMP                                                      ->51
         48    >   ASSIGN_DIM                                               !1
         49        OP_DATA                                                  !3
         50        PRE_INC                                                  !4
         51    >   IS_SMALLER                                               !4, !2
         52      > JMPNZ                                                    ~29, ->48
   22    53    > > JMP                                                      ->44
         54    >   FE_FREE                                                  $23
   25    55        INIT_FCALL                                               'print_r'
         56        SEND_VAR                                                 !1
         57        DO_ICALL                                                 
         58      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
129.92 ms | 1405 KiB | 19 Q