3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function Price($c,$pid){ //return '0.00'; $p=array(); $mintcard=array(); foreach($c as $comp => $competitor){ $p[] = $competitor['price']; if($comp=='mtgmintcard'){ $mintcard['stock'] = $competitor['stock']; $mintcard['price'] = $competitor['price']; } } if(count($mintcard)===0) return false; $min = _MIN($p); $avg = _AVG($p); if($mintcard['stock']>=1){ switch(true){ case $min <= 0.10: $price = (4 > 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 = false; break; } }else{ //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; } return ($mintcard['stock']===-1 ? FoilPrice($price) : $price); } function FoilPrice($price){ switch(true){ case $price <= 1.00: $price = bcmul($price,2.5,2); break; case $price > 1.00 && $price <= 10.00: $price = bcmul($price,2,2); break; case $price > 10.00: $price = bcmul($price,1.5,2); break; } return $price; } function _AVG($args){ /*$count = func_num_args(); $args = func_get_args();*/ $count = count($args); $sum = array_sum($args); echo bcdiv($sum,$count,2); return bcdiv($sum,$count,2); } function _MIN($args){ echo min($args); return min($args); } $c=array( 'mtgmintcard' => array( 'price' => 2.50, 'stock' => '-1' ), 'manaleak' => array( 'price' => 4.99, 'stock' => 5 ), 'magicmadhouse' => array( 'price' => 4.99, 'stock' => 1 ) ); $pid=1; echo Price($c,$pid);
Output for 4.3.0 - 5.5.33, 5.5.35 - 5.6.19, 5.6.21 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.4, 7.0.6 - 7.1.0
2.54.164.16
Output for 7.0.5
2.5 Fatal error: Uncaught Error: Call to undefined function bcdiv() in /in/ego8s:50 Stack trace: #0 /in/ego8s(15): _AVG(Array) #1 /in/ego8s(72): Price(Array, 1) #2 {main} thrown in /in/ego8s on line 50
Process exited with code 255.
Output for 5.5.34, 5.6.20
2.5 Fatal error: Call to undefined function bcdiv() in /in/ego8s on line 50
Process exited with code 255.