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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.11 ms | 941 KiB | 20 Q