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) { echo "order: " . $order . PHP_EOL; $remainingValue = $order; foreach($vouchers as $id => $voucher) { echo "voucher : " . $voucher . PHP_EOL; $discount = max (0, min ($remainingValue, $voucher)); $discounts[$order][$id] = $discount; $remainingValue -= $discount; } } var_dump($discounts);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 31
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 29
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 29
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 29
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/abumG
function name:  (null)
number of ops:  36
compiled vars:  !0 = $vouchers, !1 = $discounts, !2 = $orders, !3 = $order, !4 = $remainingValue, !5 = $voucher, !6 = $id, !7 = $discount
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, ->31
          4    > > FE_FETCH_R                                               $11, !3, ->31
   12     5    >   CONCAT                                           ~12     'order%3A+', !3
          6        CONCAT                                           ~13     ~12, '%0A'
          7        ECHO                                                     ~13
   14     8        ASSIGN                                                   !4, !3
   15     9      > FE_RESET_R                                       $15     !0, ->29
         10    > > FE_FETCH_R                                       ~16     $15, !5, ->29
         11    >   ASSIGN                                                   !6, ~16
   16    12        CONCAT                                           ~18     'voucher+%3A+', !5
         13        CONCAT                                           ~19     ~18, '%0A'
         14        ECHO                                                     ~19
   17    15        INIT_FCALL                                               'max'
         16        SEND_VAL                                                 0
         17        INIT_FCALL                                               'min'
         18        SEND_VAR                                                 !4
         19        SEND_VAR                                                 !5
         20        DO_ICALL                                         $20     
         21        SEND_VAR                                                 $20
         22        DO_ICALL                                         $21     
         23        ASSIGN                                                   !7, $21
   18    24        FETCH_DIM_W                                      $23     !1, !3
         25        ASSIGN_DIM                                               $23, !6
         26        OP_DATA                                                  !7
   19    27        ASSIGN_OP                                     2          !4, !7
   15    28      > JMP                                                      ->10
         29    >   FE_FREE                                                  $15
   11    30      > JMP                                                      ->4
         31    >   FE_FREE                                                  $11
   23    32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !1
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.05 ms | 1400 KiB | 19 Q