3v4l.org

run code in 300+ PHP versions simultaneously
<?php $weight_distribution = [ '5' => 0, '10' => 6, '15' => 7, '20' => 3, ]; function distribute_weights($weight, &$distribution) { while ($weight > 0) { foreach ($distribution as $max => $count) { if ($weight <= $max) { break; } } ++$distribution[$max]; $weight -= $max; } } distribute_weights(21, $weight_distribution); var_export($weight_distribution);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dYoTS
function name:  (null)
number of ops:  9
compiled vars:  !0 = $weight_distribution
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'distribute_weights'
          2        SEND_VAL                                                 21
          3        SEND_REF                                                 !0
          4        DO_FCALL                                      0          
   24     5        INIT_FCALL                                               'var_export'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function distribute_weights:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 10
filename:       /in/dYoTS
function name:  distribute_weights
number of ops:  17
compiled vars:  !0 = $weight, !1 = $distribution, !2 = $count, !3 = $max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2      > JMP                                                      ->14
   12     3    > > FE_RESET_R                                       $4      !1, ->10
          4    > > FE_FETCH_R                                       ~5      $4, !2, ->10
          5    >   ASSIGN                                                   !3, ~5
   13     6        IS_SMALLER_OR_EQUAL                                      !0, !3
          7      > JMPZ                                                     ~7, ->9
   14     8    > > JMP                                                      ->10
   12     9    > > JMP                                                      ->4
         10    >   FE_FREE                                                  $4
   17    11        FETCH_DIM_RW                                     $8      !1, !3
         12        PRE_INC                                                  $8
   18    13        ASSIGN_OP                                     2          !0, !3
   11    14    >   IS_SMALLER                                               0, !0
         15      > JMPNZ                                                    ~11, ->3
   20    16    > > RETURN                                                   null

End of function distribute_weights

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.07 ms | 1008 KiB | 15 Q