Skip to content

Instantly share code, notes, and snippets.

@rashid2003
Created October 9, 2019 03:35
Show Gist options
  • Save rashid2003/328b99840ce55967c0c506f280bab7db to your computer and use it in GitHub Desktop.
Save rashid2003/328b99840ce55967c0c506f280bab7db to your computer and use it in GitHub Desktop.
// we imagine the ( sccaned ) is array of scaned items the function will be like :
<?php
$sccaned = array("atv", "atv", "atv", "vga", "ipd", "ipd", "ipd", "ipd", "ipd");
$atv_price = 109.50;
$mbp_price = 1399.99;
$vga_price = 30.00;
$ipd_price = 549.99;
$size = sizeof($sccaned);
for ($x = 0; $x <= $size; $x++) {
if ($sccaned[$x] == "atv") {
$atv ++;
}elseif($sccaned[$x] == "vga"){
$vga ++;
}elseif($sccaned[$x] == "ipd"){
$ipd ++;
}
};
if($atv == 3){$atv = 2; };
if($ipd > 4){$ipd_price = 499.99;};
if($vga > 0){if($mbp > 0){$vga = 0;}};
echo "Total : $", $total = $atv*$atv_price + $vga*$vga_price + $ipd*$ipd_price + $mbp*$mbp_price;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment