3v4l.org

run code in 500+ PHP versions simultaneously
<?php $types = array( "text" => 2, "image" => 3, "audio" => 2, ); $data = []; $keys = array_keys($types); $last = end($keys); while (list($type, $count) = @each($types)) { if ($count !== 0) { // push until count reaches zero $data[] = $type; // push it inside $types[$type]--; // subtract 1 count } if ($type === $last) { // if reached the end, reset the loop reset($types); } if (array_sum($types) === 0) { // end the loop if all are gone break; } } print_r($data); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 11
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 28
Branch analysis from position: 22
Branch analysis from position: 17
filename:       /in/eHenI
function name:  (null)
number of ops:  42
compiled vars:  !0 = $types, !1 = $data, !2 = $keys, !3 = $last, !4 = $count, !5 = $type
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   10     1        ASSIGN                                                       !1, <array>
          2        INIT_FCALL                                                   'array_keys'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $8      
          5        ASSIGN                                                       !2, $8
          6        INIT_FCALL                                                   'end'
          7        SEND_REF                                                     !2
          8        DO_ICALL                                             $10     
          9        ASSIGN                                                       !3, $10
   11    10      > JMP                                                          ->28
   12    11    >   IS_NOT_IDENTICAL                                             !4, 0
         12      > JMPZ                                                         ~12, ->17
   13    13    >   ASSIGN_DIM                                                   !1
         14        OP_DATA                                                      !5
   14    15        FETCH_DIM_RW                                         $14     !0, !5
         16        PRE_DEC                                                      $14
   17    17    >   IS_IDENTICAL                                                 !5, !3
         18      > JMPZ                                                         ~16, ->22
   18    19    >   INIT_FCALL                                                   'reset'
         20        SEND_REF                                                     !0
         21        DO_ICALL                                                     
   20    22    >   INIT_FCALL                                                   'array_sum'
         23        SEND_VAR                                                     !0
         24        DO_ICALL                                             $18     
         25        IS_IDENTICAL                                                 $18, 0
         26      > JMPZ                                                         ~19, ->28
   21    27    > > JMP                                                          ->38
   11    28    >   BEGIN_SILENCE                                        ~20     
         29        INIT_FCALL_BY_NAME                                           'each'
         30        SEND_VAR_EX                                                  !0
         31        DO_FCALL                                          0  $21     
         32        END_SILENCE                                                  ~20
         33        FETCH_LIST_R                                         $22     $21, 0
         34        ASSIGN                                                       !5, $22
         35        FETCH_LIST_R                                         $24     $21, 1
         36        ASSIGN                                                       !4, $24
         37      > JMPNZ                                                        $21, ->11
   25    38    >   INIT_FCALL                                                   'print_r'
         39        SEND_VAR                                                     !1
         40        DO_ICALL                                                     
   26    41      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.32 ms | 2134 KiB | 18 Q