Jump to content

explode strings to get numbers and do calculation?


StefanRSA

Recommended Posts

I am getting numbers from a string and my code look like:

foreach ($gresult as $x ){
  if(!empty($x)){
$unit_result= explode(",",$x);
$price = $unit_result[6];

echo $price;
}
}

$price can contain 3000 and 1500 but if I echo it gives me 30001500.

How can I ad $price to give me the total? (Like 3000 + 1500 = 4500)

In other words. I just want the sum of $price.

 

Can anybody help me out here please?

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.