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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.1 ms | 1400 KiB | 19 Q