3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vouchers = array( 1 => 100, 3 => 150, 5 => 100 ); $discounts = array(); $orders = [50, 100, 200, 300, 500, 1000]; foreach ($orders as $order) { foreach ($vouchers as $voucher) { $discounts[$order][$voucher] = 0; } $remainingValue = $order; $voucher = array_pop($vouchers); if ($voucher === null) { continue; } while($remainingValue > 0 && $voucher !== null) { $value = min ($remainingValue, $voucher); $discounts[$order][$voucher] = $value; $voucher = array_pop($vouchers); } } var_dump($discounts);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 39
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 39
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 21
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
Branch analysis from position: 37
Branch analysis from position: 37
Branch analysis from position: 11
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/e60Pv
function name:  (null)
number of ops:  44
compiled vars:  !0 = $vouchers, !1 = $discounts, !2 = $orders, !3 = $order, !4 = $voucher, !5 = $remainingValue, !6 = $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                                       $10     !2, ->39
          4    > > FE_FETCH_R                                               $10, !3, ->39
   12     5    > > FE_RESET_R                                       $11     !0, ->11
          6    > > FE_FETCH_R                                               $11, !4, ->11
   13     7    >   FETCH_DIM_W                                      $12     !1, !3
          8        ASSIGN_DIM                                               $12, !4
          9        OP_DATA                                                  0
   12    10      > JMP                                                      ->6
         11    >   FE_FREE                                                  $11
   16    12        ASSIGN                                                   !5, !3
   17    13        INIT_FCALL                                               'array_pop'
         14        SEND_REF                                                 !0
         15        DO_ICALL                                         $15     
         16        ASSIGN                                                   !4, $15
   18    17        TYPE_CHECK                                    2          !4
         18      > JMPZ                                                     ~17, ->20
   19    19    > > JMP                                                      ->4
   22    20    > > JMP                                                      ->33
   23    21    >   INIT_FCALL                                               'min'
         22        SEND_VAR                                                 !5
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $18     
         25        ASSIGN                                                   !6, $18
   24    26        FETCH_DIM_W                                      $20     !1, !3
         27        ASSIGN_DIM                                               $20, !4
         28        OP_DATA                                                  !6
   25    29        INIT_FCALL                                               'array_pop'
         30        SEND_REF                                                 !0
         31        DO_ICALL                                         $22     
         32        ASSIGN                                                   !4, $22
   22    33    >   IS_SMALLER                                       ~24     0, !5
         34      > JMPZ_EX                                          ~24     ~24, ->37
         35    >   TYPE_CHECK                                  1020  ~25     !4
         36        BOOL                                             ~24     ~25
         37    > > JMPNZ                                                    ~24, ->21
   11    38    > > JMP                                                      ->4
         39    >   FE_FREE                                                  $10
   29    40        INIT_FCALL                                               'var_dump'
         41        SEND_VAR                                                 !1
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.89 ms | 1400 KiB | 19 Q