Jump to content

Help with "implode"


DBookatay

Recommended Posts

I'm creating a script for warranty rates, and am having a problem with the "math" aspect of it.

Different factors (year/ mileage/ 4x4) determines the surcharges that has to be added to the base price: $1380.

Here is what I mean:

 

$base = 1380;
if ($class == "2") {$surcharge[] = 550;}
if ($row['mileage'] > "99999" && $row['mileage'] < "125000") {$surcharge[] = 200;}
if ($row['mileage'] > "125000" && $row['mileage'] < "150001") {$surcharge[] = 400;}
if ($row['drivetrain'] == "AWD" || $row['drivetrain'] == "4x4") {$surcharge[] = 150;}
if ($row['fuel'] == "Diesel") {$surcharge[] = 100;}

if ($row['year'] = date("Y")-11) {
$surcharge[] = 50;
} elseif ($row['year'] = date("Y")-12) {
$surcharge[] = 100;
} elseif ($row['year'] = date("Y")-13) {
$surcharge[] = 200;
}

if ($surcharge) {$surcharges = implode("+", $surcharge);}
$warr_Extended = $base + $surcharges;

 

The issue is that "$surcharges" is displaying like "200+100+50," instead of adding the values of the "surcharges", in this case 350.

 

Is there a better way that I should be doing this?

Link to comment
https://forums.phpfreaks.com/topic/233024-help-with-implode/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.