Jump to content

[SOLVED] adding of variables


timmah1

Recommended Posts

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

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...

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

 

 

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.