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) { continue; } 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 = 42
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 42
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 = 22
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 23
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
Branch analysis from position: 40
Branch analysis from position: 40
Branch analysis from position: 13
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/KChR6
function name:  (null)
number of ops:  47
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, ->42
          4    > > FE_FETCH_R                                               $12, !3, ->42
   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, ->22
   20    21    > > JMP                                                      ->4
   23    22    > > JMP                                                      ->36
   24    23    >   INIT_FCALL                                               'min'
         24        SEND_VAR                                                 !7
         25        SEND_VAR                                                 !5
         26        DO_ICALL                                         $23     
         27        ASSIGN                                                   !8, $23
   25    28        FETCH_DIM_W                                      $25     !1, !3
         29        ASSIGN_DIM                                               $25, !6
         30        OP_DATA                                                  !8
   26    31        INIT_FCALL                                               'array_pop'
         32        SEND_REF                                                 !4
         33        DO_ICALL                                         $27     
         34        ASSIGN                                                   !5, $27
   27    35        ASSIGN_OP                                     2          !7, !8
   23    36    >   IS_SMALLER                                       ~30     0, !7
         37      > JMPZ_EX                                          ~30     ~30, ->40
         38    >   TYPE_CHECK                                  1020  ~31     !5
         39        BOOL                                             ~30     ~31
         40    > > JMPNZ                                                    ~30, ->23
   11    41    > > JMP                                                      ->4
         42    >   FE_FREE                                                  $12
   31    43        INIT_FCALL                                               'var_dump'
         44        SEND_VAR                                                 !1
         45        DO_ICALL                                                 
         46      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.18 ms | 1400 KiB | 19 Q