3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vouchers = array( 1 => 100, 3 => 150, 5 => 100 ); $discounts = array(); $orders = array(50, 100, 200, 300, 500, 1000); foreach ($orders as $order) { $vouchers2 = $vouchers; foreach ($vouchers2 as $id => $voucher) { $discounts[$order][$id] = 0; } $remainingValue = $order; $id = key($vouchers2); $voucher = array_pop($vouchers2); if ($voucher === null) { echo 'exiting for order '. $order . PHP_EOL; continue; } echo "order: " . $order . PHP_EOL; echo "voucher : " . $voucher . PHP_EOL; while($remainingValue > 0 && $voucher !== null) { $value = min ($remainingValue, $voucher); $id = key($vouchers); $discounts[$order][$id] = $value; $voucher = array_pop($vouchers2); $remainingValue -= $value; } } var_dump($discounts);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 59
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 59
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 46) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 36
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
Branch analysis from position: 57
Branch analysis from position: 57
Branch analysis from position: 13
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
filename:       /in/MAsG9
function name:  (null)
number of ops:  64
compiled vars:  !0 = $vouchers, !1 = $discounts, !2 = $orders, !3 = $order, !4 = $vouchers2, !5 = $voucher, !6 = $id, !7 = $remainingValue, !8 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   10     2        ASSIGN                                                   !2, <array>
   11     3      > FE_RESET_R                                       $12     !2, ->59
          4    > > FE_FETCH_R                                               $12, !3, ->59
   12     5    >   ASSIGN                                                   !4, !0
   13     6      > FE_RESET_R                                       $14     !4, ->13
          7    > > FE_FETCH_R                                       ~15     $14, !5, ->13
          8    >   ASSIGN                                                   !6, ~15
   14     9        FETCH_DIM_W                                      $17     !1, !3
         10        ASSIGN_DIM                                               $17, !6
         11        OP_DATA                                                  0
   13    12      > JMP                                                      ->7
         13    >   FE_FREE                                                  $14
   17    14        ASSIGN                                                   !7, !3
   18    15        INIT_FCALL                                               'key'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                         $20     
         18        ASSIGN                                                   !6, $20
   19    19        INIT_FCALL                                               'array_pop'
         20        SEND_REF                                                 !4
         21        DO_ICALL                                         $22     
         22        ASSIGN                                                   !5, $22
   20    23        TYPE_CHECK                                    2          !5
         24      > JMPZ                                                     ~24, ->29
   21    25    >   CONCAT                                           ~25     'exiting+for+order+', !3
         26        CONCAT                                           ~26     ~25, '%0A'
         27        ECHO                                                     ~26
   22    28      > JMP                                                      ->4
   24    29    >   CONCAT                                           ~27     'order%3A+', !3
         30        CONCAT                                           ~28     ~27, '%0A'
         31        ECHO                                                     ~28
   25    32        CONCAT                                           ~29     'voucher+%3A+', !5
         33        CONCAT                                           ~30     ~29, '%0A'
         34        ECHO                                                     ~30
   26    35      > JMP                                                      ->53
   27    36    >   INIT_FCALL                                               'min'
         37        SEND_VAR                                                 !7
         38        SEND_VAR                                                 !5
         39        DO_ICALL                                         $31     
         40        ASSIGN                                                   !8, $31
   28    41        INIT_FCALL                                               'key'
         42        SEND_VAR                                                 !0
         43        DO_ICALL                                         $33     
         44        ASSIGN                                                   !6, $33
   29    45        FETCH_DIM_W                                      $35     !1, !3
         46        ASSIGN_DIM                                               $35, !6
         47        OP_DATA                                                  !8
   31    48        INIT_FCALL                                               'array_pop'
         49        SEND_REF                                                 !4
         50        DO_ICALL                                         $37     
         51        ASSIGN                                                   !5, $37
   32    52        ASSIGN_OP                                     2          !7, !8
   26    53    >   IS_SMALLER                                       ~40     0, !7
         54      > JMPZ_EX                                          ~40     ~40, ->57
         55    >   TYPE_CHECK                                  1020  ~41     !5
         56        BOOL                                             ~40     ~41
         57    > > JMPNZ                                                    ~40, ->36
   11    58    > > JMP                                                      ->4
         59    >   FE_FREE                                                  $12
   36    60        INIT_FCALL                                               'var_dump'
         61        SEND_VAR                                                 !1
         62        DO_ICALL                                                 
         63      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.94 ms | 1400 KiB | 21 Q