3v4l.org

run code in 300+ PHP versions simultaneously
<?php $total_capacity = 100; $resources = array('gold'=>125,'stone'=>30, 'food'=>0); $loot = array(); asort($resources); foreach($resources as $type => $resource) { $max = floor(($total_capacity-array_sum($loot))/(3-count($loot))); // var_dump(count($loot)); if($max > $resource) { $loot[$type] = $resource; } else { $loot[$type] = $max; } } print_r($loot); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 28
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 28
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/EauJh
function name:  (null)
number of ops:  33
compiled vars:  !0 = $total_capacity, !1 = $resources, !2 = $loot, !3 = $resource, !4 = $type, !5 = $max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 100
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    7     3        INIT_FCALL                                               'asort'
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
    8     6      > FE_RESET_R                                       $10     !1, ->28
          7    > > FE_FETCH_R                                       ~11     $10, !3, ->28
          8    >   ASSIGN                                                   !4, ~11
   10     9        INIT_FCALL                                               'floor'
         10        INIT_FCALL                                               'array_sum'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $13     
         13        SUB                                              ~14     !0, $13
         14        COUNT                                            ~15     !2
         15        SUB                                              ~16     3, ~15
         16        DIV                                              ~17     ~14, ~16
         17        SEND_VAL                                                 ~17
         18        DO_ICALL                                         $18     
         19        ASSIGN                                                   !5, $18
   12    20        IS_SMALLER                                               !3, !5
         21      > JMPZ                                                     ~20, ->25
   13    22    >   ASSIGN_DIM                                               !2, !4
         23        OP_DATA                                                  !3
         24      > JMP                                                      ->27
   16    25    >   ASSIGN_DIM                                               !2, !4
         26        OP_DATA                                                  !5
    8    27    > > JMP                                                      ->7
         28    >   FE_FREE                                                  $10
   20    29        INIT_FCALL                                               'print_r'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                                 
   22    32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.19 ms | 1396 KiB | 21 Q