Monday 15 September 2014

for loop - PHP Find right value for x when x + 20% = 276 -



for loop - PHP Find right value for x when x + 20% = 276 -

i need able solve x value x + 20% = y script. y value known in script, x needs solved.

i've tried loop.

the echo $i should output 230, @ moment script doesn't homecoming (blank white screen)

$amount = 276; for($i = 1; $i<300; $i++) { if($i+20% == $amount) { echo $i; } }

basic maths: calculate 120% of value $i:

if (($i/100)*120 == $amount)

or improve still, calculate value $i if know value 120%:

$i = ($amount/120)*100;

which can simplified to:

$i = ($amount/12)*10; //same goes first snippet: if (($i/10)*12 == $amount)

php for-loop

No comments:

Post a Comment