Jump to content

Calculating with variables


xoluz

Recommended Posts

Hi was wondering something, I've got the following code now:

[code]
$ruletotal = $array['amount'] * $array['price'];
$formtotal = array_sum($ruletotal)
[/code]

This thing works imo, but now I want to add something to it. When the '$formtotal' is more than 50 000, I want to calculate 10% of it. So i got this added, but something isn't working:

[code]
if ($formtotal = 50000) {
$discount = $formtotal /100*10; }
else { echo 'no discount';}
$total = $formtotal - $discount;
echo 'Total: $total';
[/code]

Could someone help me out here..? :)
Link to comment
https://forums.phpfreaks.com/topic/5175-calculating-with-variables/
Share on other sites

You need to use "==" not "=". But you said you wanted this to happen "When the '$formtotal' is more than 50 000"

[code]<?php
if ($formtotal > 50000)
     $discount = $formtotal * 0.1;
else
     echo 'no discount<br>';
$total = $formtotal - $discount;
echo 'Total: $total';
?>[/code]

Ken
[!--quoteo(post=355956:date=Mar 18 2006, 04:05 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 18 2006, 04:05 AM) [snapback]355956[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You need to use "==" not "=". But you said you wanted this to happen "When the '$formtotal' is more than 50 000"

[code]<?php
if ($formtotal > 50000)
     $discount = $formtotal * 0.1;
else
     echo 'no discount<br>';
$total = $formtotal - $discount;
echo 'Total: $total';
?>[/code]

Ken
[/quote]

Thanks! That works perfect :)

And I forgot about the ==, it should be > like you said ;)

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.