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; $voucher = array_pop($vouchers2); if ($voucher === null) { echo 'exiting for order '. $order . PHP_EOL; continue; } echo "voucher : " . $voucher . PHP_EOL; while($remainingValue > 0 && $voucher !== null) { $value = min ($remainingValue, $voucher); $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 = 48
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 48
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 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 29
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
Branch analysis from position: 46
Branch analysis from position: 46
Branch analysis from position: 13
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/eWu9Q
function name:  (null)
number of ops:  53
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, ->48
          4    > > FE_FETCH_R                                               $12, !3, ->48
   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                                               'array_pop'
         16        SEND_REF                                                 !4
         17        DO_ICALL                                         $20     
         18        ASSIGN                                                   !5, $20
   19    19        TYPE_CHECK                                    2          !5
         20      > JMPZ                                                     ~22, ->25
   20    21    >   CONCAT                                           ~23     'exiting+for+order+', !3
         22        CONCAT                                           ~24     ~23, '%0A'
         23        ECHO                                                     ~24
   21    24      > JMP                                                      ->4
   23    25    >   CONCAT                                           ~25     'voucher+%3A+', !5
         26        CONCAT                                           ~26     ~25, '%0A'
         27        ECHO                                                     ~26
   24    28      > JMP                                                      ->42
   25    29    >   INIT_FCALL                                               'min'
         30        SEND_VAR                                                 !7
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                         $27     
         33        ASSIGN                                                   !8, $27
   26    34        FETCH_DIM_W                                      $29     !1, !3
         35        ASSIGN_DIM                                               $29, !6
         36        OP_DATA                                                  !8
   27    37        INIT_FCALL                                               'array_pop'
         38        SEND_REF                                                 !4
         39        DO_ICALL                                         $31     
         40        ASSIGN                                                   !5, $31
   28    41        ASSIGN_OP                                     2          !7, !8
   24    42    >   IS_SMALLER                                       ~34     0, !7
         43      > JMPZ_EX                                          ~34     ~34, ->46
         44    >   TYPE_CHECK                                  1020  ~35     !5
         45        BOOL                                             ~34     ~35
         46    > > JMPNZ                                                    ~34, ->29
   11    47    > > JMP                                                      ->4
         48    >   FE_FREE                                                  $12
   32    49        INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !1
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.69 ms | 1405 KiB | 19 Q