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); } } var_dump($discounts);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 40
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 40
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 = 34
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 22
Branch analysis from position: 39
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 = 36, Position 2 = 38
Branch analysis from position: 36
Branch analysis from position: 38
Branch analysis from position: 38
Branch analysis from position: 12
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/kq4uE
function name:  (null)
number of ops:  45
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, ->40
          4    > > FE_FETCH_R                                               $11, !3, ->40
   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                                                      ->34
   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
   23    34    >   IS_SMALLER                                       ~26     0, !6
         35      > JMPZ_EX                                          ~26     ~26, ->38
         36    >   TYPE_CHECK                                  1020  ~27     !5
         37        BOOL                                             ~26     ~27
         38    > > JMPNZ                                                    ~26, ->22
   11    39    > > JMP                                                      ->4
         40    >   FE_FREE                                                  $11
   30    41        INIT_FCALL                                               'var_dump'
         42        SEND_VAR                                                 !1
         43        DO_ICALL                                                 
         44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.1 ms | 1392 KiB | 19 Q