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'] = (int)$competitor['stock']; $mintcard['price'] = (float)$competitor['price']; } } if(count($mintcard)===0) return false; $min = _MIN($p); $avg = _AVG($p); if($mintcard['stock']>=1 || $mintcard['stock']===-1){ 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,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; } }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; } return ($mintcard['stock']===-1 ? FoilPrice((float)$price) : (float)$price); } function FoilPrice($price){ switch(true){ case $price <= 1.00: $price = bcmul($price,3,2); break; case $price > 1.00 && $price <= 10.00: $price = bcmul($price,2.5,2); break; case $price > 10.00: $price = bcmul($price,2,2); break; } return (float)$price; } function _AVG($args){ /*$count = func_num_args(); $args = func_get_args();*/ $count = count($args); $sum = array_sum($args); return (float)bcdiv($sum,$count,2); } function _MIN($args){ return (float)min($args); } $c = array('mtgmintcard' => array('price' => 9.57,'stock' => -1), 'magicmadhouse' => array('price' => 17.09, 'stock' => -1), 'manaleak' => array('price' => 16.99,'stock' => -1) ); echo Price($c,1);
Output for 4.3.0 - 7.1.0
23.67