Jump to content

[SOLVED] Adding $Value of array, $Value + $Value


UpcomingPhpDev

Recommended Posts

Hi phpfreaks, Im having a problem that I belive can be solved by a simple solution but I just cant seem to do it, Ive tried and tested around 2 hours of different codeing and methods but I cant seem to get it, il rewrite similar code thats easy for you guys to see.

 

 

<?php

$Numbers = "4003 4129 10249 20493";

$NumbersArray = explode(" ",$Numbers);

 

  foreach($NumbersArray as $Key => $Value)

  {

      //I need to add up all those $Value keys into 1 variable

  }

 

?>

 

Thanks in advance.

$TotalNumbers+=$Value

 

Thanks, Cant belive I didnt do this.

 

<pre>
<?php
$Numbers = "4003 4129 10249 20493";
echo $Total = array_sum(explode(' ',$Numbers));
?>
</pre>

Thanks, I didnt Know about this function, Atleast I learned something new.

 

Thanks guys

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.