3v4l.org

run code in 300+ PHP versions simultaneously
<?php function Price($c,$pid){ //return '0.00'; $p=array(); $mintcard=array(); if(count($c)===0) return false; foreach($c as $comp => $competitor){ $p[] = $competitor['price']; if($comp=='mtgmintcard'){ $mintcard['stock'] = (int)$competitor['stock']; $mintcard['price'] = (float)$competitor['price']; } } if(count($mintcard)===0) return false; $min = _MIN($p); $avg = _AVG($p); if($mintcard['stock']===-1){ $foil=1; $pid = 40230; if($pid!==false){ $mintcard['stock'] = 24; }else{ $mintcard['stock'] = 0; } }else{ $foil=0; } if($mintcard['stock']>=1){ switch(true){ case $min <= 0.10: $price = (30 > 35 ? 0.05 : $min); break; case $min > 0.10 && $min < 0.16: $price = bcmul($min,1,2); break; case $min >= 0.16 && $min <= 0.99: $price = bcmul($avg,0.95,2); break; case $min >= 1.00 && $min <= 1.99: $price = bcdiv(bcmul((bcadd($avg,$mintcard['price'],2)),0.95,2),2,2) ; break; // + mtg price case $min >= 2.00: $price = bcmul($min,0.99,2); break; default: $price = 0; break; } }elseif($mintcard['stock']===0){ //switch(true){ /*case $min <= 0.10: $price = (_SQL_FETCHSTOCK($pid) > 35 ? 0.05 : $min); break; case $min >= 0.10 && $min < 0.16: $price = bcmul($min,0.99,2); break; case $min >= 0.16 && $min <= 0.99: $price = bcmul($avg,0.95,2); break; case $min >= 1.00 : $price = bcdiv(bcmul((bcadd($avg,$mintcard['price'],2)),0.95,2),2,2); break; // + mtg price default: $price = false; break;*/ //} $price = $avg; } if($foil===1){ $foilPrice = FoilPrice($price); //echo ('pricing '.$pid.' Foil identified: increased price from '.(float)$price.' to '.$foilPrice); $price = $foilPrice; } return (float)$price; } function FoilPrice($price){ switch(true){ case $price <= 1.00: $fprice = bcmul($price,3,2); break; case $price > 1.00 && $price <= 10.00: $fprice = bcmul($price,2.5,2); break; case $price > 10.00: $fprice = bcmul($price,2,2); break; } return $fprice; } function _AVG($args){ /*$count = func_num_args(); $args = func_get_args();*/ $count = count($args); $sum = array_sum($args); return bcdiv($sum,$count,2); } function _MIN($args){ return min($args); } $arr = array( "mtgmintcard"=> array( "date_id"=>(int)67, "price"=>(float)0.2, "stock"=>(int)-1 ), "manaleak"=> array( "date_id"=>(int)67, "price"=>(float)0.35, "stock"=>(int)-1 ), "magicmadhouse"=> array( "date_id"=>(int)67, "price"=>(float)0.49, "stock"=>(int)-1 ), ); echo Price($arr,57521);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mDpbE
function name:  (null)
number of ops:  28
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   CAST                                          4  ~1      67
          1        INIT_ARRAY                                       ~2      ~1, 'date_id'
   76     2        CAST                                          5  ~3      0.2
          3        ADD_ARRAY_ELEMENT                                ~2      ~3, 'price'
   77     4        CAST                                          4  ~4      -1
          5        ADD_ARRAY_ELEMENT                                ~2      ~4, 'stock'
          6        INIT_ARRAY                                       ~5      ~2, 'mtgmintcard'
   81     7        CAST                                          4  ~6      67
          8        INIT_ARRAY                                       ~7      ~6, 'date_id'
   82     9        CAST                                          5  ~8      0.35
         10        ADD_ARRAY_ELEMENT                                ~7      ~8, 'price'
   83    11        CAST                                          4  ~9      -1
         12        ADD_ARRAY_ELEMENT                                ~7      ~9, 'stock'
         13        ADD_ARRAY_ELEMENT                                ~5      ~7, 'manaleak'
   87    14        CAST                                          4  ~10     67
         15        INIT_ARRAY                                       ~11     ~10, 'date_id'
   88    16        CAST                                          5  ~12     0.49
         17        ADD_ARRAY_ELEMENT                                ~11     ~12, 'price'
   89    18        CAST                                          4  ~13     -1
         19        ADD_ARRAY_ELEMENT                                ~11     ~13, 'stock'
         20        ADD_ARRAY_ELEMENT                                ~5      ~11, 'magicmadhouse'
   72    21        ASSIGN                                                   !0, ~5
   92    22        INIT_FCALL                                               'price'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 57521
         25        DO_FCALL                                      0  $15     
         26        ECHO                                                     $15
         27      > RETURN                                                   1

Function price:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 25
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 24
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 51
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 124
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 75
Branch analysis from position: 57
2 jumps found. (Code = 46) Position 1 = 59, Position 2 = 61
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 81
Branch analysis from position: 62
2 jumps found. (Code = 46) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 88
Branch analysis from position: 67
2 jumps found. (Code = 46) Position 1 = 69, Position 2 = 71
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 95
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 114
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 121
Branch analysis from position: 121
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
1 jumps found. (Code = 42) Position 1 = 128
Branch analysis from position: 128
2 jumps found. (Code = 43) Position 1 = 130, Position 2 = 135
Branch analysis from position: 130
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 135
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 71
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 66
Branch analysis from position: 81
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 61
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 78
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 124
2 jumps found. (Code = 43) Position 1 = 127, Position 2 = 128
Branch analysis from position: 127
2 jumps found. (Code = 43) Position 1 = 130, Position 2 = 135
Branch analysis from position: 130
Branch analysis from position: 135
Branch analysis from position: 128
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 124
Branch analysis from position: 55
Branch analysis from position: 124
Branch analysis from position: 25
filename:       /in/mDpbE
function name:  Price
number of ops:  138
compiled vars:  !0 = $c, !1 = $pid, !2 = $p, !3 = $mintcard, !4 = $competitor, !5 = $comp, !6 = $min, !7 = $avg, !8 = $foil, !9 = $price, !10 = $foilPrice
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        ASSIGN                                                   !3, <array>
    6     4        COUNT                                            ~13     !0
          5        IS_IDENTICAL                                             ~13, 0
          6      > JMPZ                                                     ~14, ->8
          7    > > RETURN                                                   <false>
    7     8    > > FE_RESET_R                                       $15     !0, ->25
          9    > > FE_FETCH_R                                       ~16     $15, !4, ->25
         10    >   ASSIGN                                                   !5, ~16
    8    11        FETCH_DIM_R                                      ~19     !4, 'price'
         12        ASSIGN_DIM                                               !2
         13        OP_DATA                                                  ~19
    9    14        IS_EQUAL                                                 !5, 'mtgmintcard'
         15      > JMPZ                                                     ~20, ->24
   10    16    >   FETCH_DIM_R                                      ~22     !4, 'stock'
         17        CAST                                          4  ~23     ~22
         18        ASSIGN_DIM                                               !3, 'stock'
         19        OP_DATA                                                  ~23
   11    20        FETCH_DIM_R                                      ~25     !4, 'price'
         21        CAST                                          5  ~26     ~25
         22        ASSIGN_DIM                                               !3, 'price'
         23        OP_DATA                                                  ~26
    7    24    > > JMP                                                      ->9
         25    >   FE_FREE                                                  $15
   14    26        COUNT                                            ~27     !3
         27        IS_IDENTICAL                                             ~27, 0
         28      > JMPZ                                                     ~28, ->30
         29    > > RETURN                                                   <false>
   15    30    >   INIT_FCALL_BY_NAME                                       '_MIN'
         31        SEND_VAR_EX                                              !2
         32        DO_FCALL                                      0  $29     
         33        ASSIGN                                                   !6, $29
   16    34        INIT_FCALL_BY_NAME                                       '_AVG'
         35        SEND_VAR_EX                                              !2
         36        DO_FCALL                                      0  $31     
         37        ASSIGN                                                   !7, $31
   17    38        FETCH_DIM_R                                      ~33     !3, 'stock'
         39        IS_IDENTICAL                                             ~33, -1
         40      > JMPZ                                                     ~34, ->51
   18    41    >   ASSIGN                                                   !8, 1
   19    42        ASSIGN                                                   !1, 40230
   20    43        TYPE_CHECK                                  1018          !1
         44      > JMPZ                                                     ~37, ->48
   21    45    >   ASSIGN_DIM                                               !3, 'stock'
         46        OP_DATA                                                  24
         47      > JMP                                                      ->50
   23    48    >   ASSIGN_DIM                                               !3, 'stock'
         49        OP_DATA                                                  0
         50    > > JMP                                                      ->52
   26    51    >   ASSIGN                                                   !8, 0
   28    52    >   FETCH_DIM_R                                      ~41     !3, 'stock'
         53        IS_SMALLER_OR_EQUAL                                      1, ~41
         54      > JMPZ                                                     ~42, ->124
   30    55    >   IS_SMALLER_OR_EQUAL                                      !6, 0.1
         56      > JMPNZ                                                    ~44, ->75
   31    57    >   IS_SMALLER                                       ~45     0.1, !6
         58      > JMPZ_EX                                          ~45     ~45, ->61
         59    >   IS_SMALLER                                       ~46     !6, 0.16
         60        BOOL                                             ~45     ~46
         61    > > JMPNZ                                                    ~45, ->81
   32    62    >   IS_SMALLER_OR_EQUAL                              ~47     0.16, !6
         63      > JMPZ_EX                                          ~47     ~47, ->66
         64    >   IS_SMALLER_OR_EQUAL                              ~48     !6, 0.99
         65        BOOL                                             ~47     ~48
         66    > > JMPNZ                                                    ~47, ->88
   33    67    >   IS_SMALLER_OR_EQUAL                              ~49     1, !6
         68      > JMPZ_EX                                          ~49     ~49, ->71
         69    >   IS_SMALLER_OR_EQUAL                              ~50     !6, 1.99
         70        BOOL                                             ~49     ~50
         71    > > JMPNZ                                                    ~49, ->95
   34    72    >   IS_SMALLER_OR_EQUAL                                      2, !6
         73      > JMPNZ                                                    ~51, ->114
         74    > > JMP                                                      ->121
   30    75    > > JMPZ                                                     <false>, ->78
         76    >   QM_ASSIGN                                        ~52     0.05
         77      > JMP                                                      ->79
         78    >   QM_ASSIGN                                        ~52     !6
         79    >   ASSIGN                                                   !9, ~52
         80      > JMP                                                      ->123
   31    81    >   INIT_FCALL_BY_NAME                                       'bcmul'
         82        SEND_VAR_EX                                              !6
         83        SEND_VAL_EX                                              1
         84        SEND_VAL_EX                                              2
         85        DO_FCALL                                      0  $54     
         86        ASSIGN                                                   !9, $54
         87      > JMP                                                      ->123
   32    88    >   INIT_FCALL_BY_NAME                                       'bcmul'
         89        SEND_VAR_EX                                              !7
         90        SEND_VAL_EX                                              0.95
         91        SEND_VAL_EX                                              2
         92        DO_FCALL                                      0  $56     
         93        ASSIGN                                                   !9, $56
         94      > JMP                                                      ->123
   33    95    >   INIT_FCALL_BY_NAME                                       'bcdiv'
         96        INIT_FCALL_BY_NAME                                       'bcmul'
         97        INIT_FCALL_BY_NAME                                       'bcadd'
         98        SEND_VAR_EX                                              !7
         99        CHECK_FUNC_ARG                                           
        100        FETCH_DIM_FUNC_ARG                               $58     !3, 'price'
        101        SEND_FUNC_ARG                                            $58
        102        SEND_VAL_EX                                              2
        103        DO_FCALL                                      0  $59     
        104        SEND_VAR_NO_REF_EX                                       $59
        105        SEND_VAL_EX                                              0.95
        106        SEND_VAL_EX                                              2
        107        DO_FCALL                                      0  $60     
        108        SEND_VAR_NO_REF_EX                                       $60
        109        SEND_VAL_EX                                              2
        110        SEND_VAL_EX                                              2
        111        DO_FCALL                                      0  $61     
        112        ASSIGN                                                   !9, $61
        113      > JMP                                                      ->123
   34   114    >   INIT_FCALL_BY_NAME                                       'bcmul'
        115        SEND_VAR_EX                                              !6
        116        SEND_VAL_EX                                              0.99
        117        SEND_VAL_EX                                              2
        118        DO_FCALL                                      0  $63     
        119        ASSIGN                                                   !9, $63
        120      > JMP                                                      ->123
   35   121    >   ASSIGN                                                   !9, 0
        122      > JMP                                                      ->123
        123    > > JMP                                                      ->128
   37   124    >   FETCH_DIM_R                                      ~66     !3, 'stock'
        125        IS_IDENTICAL                                             ~66, 0
        126      > JMPZ                                                     ~67, ->128
   45   127    >   ASSIGN                                                   !9, !7
   47   128    >   IS_IDENTICAL                                             !8, 1
        129      > JMPZ                                                     ~69, ->135
   48   130    >   INIT_FCALL_BY_NAME                                       'FoilPrice'
        131        SEND_VAR_EX                                              !9
        132        DO_FCALL                                      0  $70     
        133        ASSIGN                                                   !10, $70
   50   134        ASSIGN                                                   !9, !10
   52   135    >   CAST                                          5  ~73     !9
        136      > RETURN                                                   ~73
   53   137*     > RETURN                                                   null

End of function price

Function foilprice:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 7
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
filename:       /in/mDpbE
function name:  FoilPrice
number of ops:  34
compiled vars:  !0 = $price, !1 = $fprice
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        IS_SMALLER_OR_EQUAL                                      !0, 1
          2      > JMPNZ                                                    ~3, ->11
   57     3    >   IS_SMALLER                                       ~4      1, !0
          4      > JMPZ_EX                                          ~4      ~4, ->7
          5    >   IS_SMALLER_OR_EQUAL                              ~5      !0, 10
          6        BOOL                                             ~4      ~5
          7    > > JMPNZ                                                    ~4, ->18
   58     8    >   IS_SMALLER                                               10, !0
          9      > JMPNZ                                                    ~6, ->25
         10    > > JMP                                                      ->32
   56    11    >   INIT_FCALL_BY_NAME                                       'bcmul'
         12        SEND_VAR_EX                                              !0
         13        SEND_VAL_EX                                              3
         14        SEND_VAL_EX                                              2
         15        DO_FCALL                                      0  $7      
         16        ASSIGN                                                   !1, $7
         17      > JMP                                                      ->32
   57    18    >   INIT_FCALL_BY_NAME                                       'bcmul'
         19        SEND_VAR_EX                                              !0
         20        SEND_VAL_EX                                              2.5
         21        SEND_VAL_EX                                              2
         22        DO_FCALL                                      0  $9      
         23        ASSIGN                                                   !1, $9
         24      > JMP                                                      ->32
   58    25    >   INIT_FCALL_BY_NAME                                       'bcmul'
         26        SEND_VAR_EX                                              !0
         27        SEND_VAL_EX                                              2
         28        SEND_VAL_EX                                              2
         29        DO_FCALL                                      0  $11     
         30        ASSIGN                                                   !1, $11
         31      > JMP                                                      ->32
   60    32    > > RETURN                                                   !1
   61    33*     > RETURN                                                   null

End of function foilprice

Function _avg:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mDpbE
function name:  _AVG
number of ops:  14
compiled vars:  !0 = $args, !1 = $count, !2 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   65     1        COUNT                                            ~3      !0
          2        ASSIGN                                                   !1, ~3
   66     3        INIT_FCALL                                               'array_sum'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !2, $5
   67     7        INIT_FCALL_BY_NAME                                       'bcdiv'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !1
         10        SEND_VAL_EX                                              2
         11        DO_FCALL                                      0  $7      
         12      > RETURN                                                   $7
   68    13*     > RETURN                                                   null

End of function _avg

Function _min:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mDpbE
function name:  _MIN
number of ops:  6
compiled vars:  !0 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   70     1        INIT_FCALL                                               'min'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   71     5*     > RETURN                                                   null

End of function _min

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.73 ms | 1422 KiB | 27 Q