PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $prices = [7,6,4,3,1]; $buyingPrice = 0; $soldingPrice = 0; $buyedDay = 0; if (count($prices) < 2) { // echo "0"; return 0; } foreach ($prices as $index => $price) { switch ($index) { case 0: $buyingPrice = $price; break; case 1: $soldingPrice = $price; break; } if ($buyingPrice > $price) { $buyingPrice = $price $buyedDay = $index } if (($index > $buyedDay) && (($price > $buyingPrice) && ($price > $soldingPrice))) { $soldingPrice = $price } } if ( ($soldingPrice > $buyingPrice) && ((soldingPrice - $buyingPrice) > 0) ) { return ($soldingPrice - $buyingPrice); } else { return 0; }
Show:  
Copy Clear