Reputation: 1
Writing a small php calculator form to display the premium price for an input numeral amount.
unfortunately there is no static formula for the scaling of cost. So I attempted if/else echo statements for the data ranges
if(
$policyamount<="10000". print("35\.00").
$policyamount<="15000". print("42\.00").
And so on. Am I approaching this correctly, or is this a case of paranoid Monday morning?
Upvotes: 0
Views: 133
Reputation: 324750
Personally, I'd define an array like this:
$prices = array(
10000 => 35,
15000 => 42,
// define more price points here
);
Then, to display the price:
$copy = $prices;
foreach($copy as $k=>$v) {
if( $policyamount <= $k) {
echo number_format($v,2);
break; // end the loop
}
}
Upvotes: 1
Reputation: 43850
Let's start with the correct syntax first
if($policyamount<=10000)
echo "35.00";
elseif ($policyamount<=15000)
echo "42.00";
Upvotes: 1