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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.65 ms | 1400 KiB | 19 Q