timmah1 Posted April 22, 2009 Share Posted April 22, 2009 This code worked fine, but now it don't Can anybody tell me what's wrong? <?php $val=substr($val,0); $price = explode(",", $val); $tmp = number_format($price[1], 2); $total_price += $tmp; echo $total_price; ?> It use to work regardless if there was one or two values for price[1] Thanks in advance Link to comment https://forums.phpfreaks.com/topic/155238-solved-adding-of-variables/ Share on other sites More sharing options...
Daniel0 Posted April 22, 2009 Share Posted April 22, 2009 On the phone... A: Foo Bar, Inc. car repair service. How can I help you? B: Hi, my car is broken. How long time will it take for you to repair it and how much will it cost? Link to comment https://forums.phpfreaks.com/topic/155238-solved-adding-of-variables/#findComment-816720 Share on other sites More sharing options...
Maq Posted April 22, 2009 Share Posted April 22, 2009 Most popular way to debug, echo variables out. Here's your output, do you see what's going on here? $val = 12345; $val=substr($val,0); //12345 $price = explode(",", $val); //[0] => 12345 $tmp = number_format($price[1], 2); //0.00 $total_price += $tmp; //0 echo $total_price; //0 ?> Like Daniel is implying, we need more information. What did you change? What happens? How did it used to work (example)? etc... Link to comment https://forums.phpfreaks.com/topic/155238-solved-adding-of-variables/#findComment-816731 Share on other sites More sharing options...
timmah1 Posted April 22, 2009 Author Share Posted April 22, 2009 Guess if Daniel would of happened to explain it that way, I would've understood what they meant, my apologies for not posting enough code. <?php while (list ($name,$val) = @each ($_POST['package_'])) { $val=substr($val,0); $price = explode(",", $val); $tmp1 = $price[1]; $total_price += $tmp1; } echo $total_price; ?> The price of $_POST['package_'] is the second value Link to comment https://forums.phpfreaks.com/topic/155238-solved-adding-of-variables/#findComment-816736 Share on other sites More sharing options...
timmah1 Posted April 22, 2009 Author Share Posted April 22, 2009 I fixed it, naturally, it was my stupid mistake $price[1] was formatted this way $price1 = "$".number_format ($price, 2); So obviously, it can't add with the dollar sign Thanks Link to comment https://forums.phpfreaks.com/topic/155238-solved-adding-of-variables/#findComment-816769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.