newbtophp Posted March 13, 2010 Share Posted March 13, 2010 How would i takeaway 20 as many times as $x from $total ? For example: if $x = 2, and $total was 50, it would output 10. :-\ Link to comment https://forums.phpfreaks.com/topic/195129-takeaway-20/ Share on other sites More sharing options...
newbtophp Posted March 13, 2010 Author Share Posted March 13, 2010 Anyone can help me? :-\ Link to comment https://forums.phpfreaks.com/topic/195129-takeaway-20/#findComment-1025679 Share on other sites More sharing options...
teamatomic Posted March 13, 2010 Share Posted March 13, 2010 Math, brackets and precedence $new_total= $total-20*$x; would do it because multiplication takes precedence over addition or subtraction but... its a good idea to get in the habit of using brackets to set precedence in math equations $new_total= $total-(20*$x); with brackets no matter the math function precedence the part in brackets will be computed first. because, if total=50 and x=2... $total-10+x would result in 42 $total-(10+x) would result in 38 HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/195129-takeaway-20/#findComment-1025733 Share on other sites More sharing options...
wildteen88 Posted March 13, 2010 Share Posted March 13, 2010 Basic maths isn't it? Just like you would in the real world echo 50 - (20 * $x); Link to comment https://forums.phpfreaks.com/topic/195129-takeaway-20/#findComment-1025735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.