DBookatay Posted April 7, 2011 Share Posted April 7, 2011 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? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 7, 2011 Share Posted April 7, 2011 You'll want to look at array_sum, instead of implode(). Implode() forms a string . . . Quote Link to comment Share on other sites More sharing options...
DBookatay Posted April 9, 2011 Author Share Posted April 9, 2011 You'll want to look at array_sum, instead of implode(). Implode() forms a string . . . Solved! Thanks!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.