How do I calculate this in PHP?



277 views

Hi 

I am a newbie to PHP and trying to build a calculator with variables. Using the elseif, how would I express the following:

Example: The cost is 8250 plus 1100 per 100000 or portion of 100000 of the purchase price exceeding 500000 and up to and including 1000000.

               Or the cost is 13750 plus 550 per 100000 or portion of 100000 of the purchase price exceeding 1000000 up to and including 5000000

               Or the cost is 35750 plus 275 per 100000 or portion of 100000 of the purchase price exceeding 5000000

Any advice or ideas will be appreciated.

Thank you.

 

asked May 28, 2014 by Zevan

1 Answer

0 votes
// A direction... 
$per = 100000 / (8250 + 1100); // 10.69
$price = rand(500001, 1000000);
$part = ($price / 100000) * $per;


answered May 28, 2014 by avibootz
edited Mar 4, 2025 by avibootz
Thank you very much avibootz. I appreciate it.
Another answer I got from a different source is: $result=8250+ceil(($price-500000)/100000)*1100;
Maybe it can help someone. Will try both and see how it goes.
...