3v4l.org

run code in 300+ PHP versions simultaneously
<?php function discount($cart){ $sum = array_sum($cart); if($sum >= 100) return 15; else if(count($cart) >= 3 and (isset($cart['A']) or isset($cart['B']))) return 10; else if(count($cart) >= 3) return 5; else return 0; } $carts = [ // product => price ['A' => 15, 'B' => 25], // no discount ['D' => 15, 'E' => 25, 'F' => 50], // any 3 ['A' => 15, 'B' => 25, 'D' => 35], // any 2 + 1 special ['A' => 15, 'B' => 25, 'C' => 50, 'D' => 75], // over amount x ]; foreach($carts as $cart){ echo (string)discount($cart), "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/hf4W0
function name:  (null)
number of ops:  12
compiled vars:  !0 = $carts, !1 = $cart
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, <array>
   18     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                               $3, !1, ->10
   19     3    >   INIT_FCALL                                               'discount'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        CAST                                          6  ~5      $4
          7        ECHO                                                     ~5
          8        ECHO                                                     '%0A'
   18     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
   20    11      > RETURN                                                   1

Function discount:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 17
filename:       /in/hf4W0
function name:  discount
number of ops:  27
compiled vars:  !0 = $cart, !1 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'array_sum'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
    5     5        IS_SMALLER_OR_EQUAL                                      100, !1
          6      > JMPZ                                                     ~4, ->9
          7    > > RETURN                                                   15
          8*       JMP                                                      ->26
    6     9    >   COUNT                                            ~5      !0
         10        IS_SMALLER_OR_EQUAL                              ~6      3, ~5
         11      > JMPZ_EX                                          ~6      ~6, ->17
         12    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~7      !0, 'A'
         13      > JMPNZ_EX                                         ~7      ~7, ->16
         14    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !0, 'B'
         15        BOOL                                             ~7      ~8
         16    >   BOOL                                             ~6      ~7
         17    > > JMPZ                                                     ~6, ->20
         18    > > RETURN                                                   10
         19*       JMP                                                      ->26
    7    20    >   COUNT                                            ~9      !0
         21        IS_SMALLER_OR_EQUAL                                      3, ~9
         22      > JMPZ                                                     ~10, ->25
         23    > > RETURN                                                   5
         24*       JMP                                                      ->26
    8    25    > > RETURN                                                   0
    9    26*     > RETURN                                                   null

End of function discount

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.5 ms | 1407 KiB | 16 Q