UpcomingPhpDev Posted August 14, 2008 Share Posted August 14, 2008 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. Quote Link to comment Share on other sites More sharing options...
Jabop Posted August 14, 2008 Share Posted August 14, 2008 $TotalNumbers+=$Value Quote Link to comment Share on other sites More sharing options...
effigy Posted August 14, 2008 Share Posted August 14, 2008 <pre> <?php $Numbers = "4003 4129 10249 20493"; echo $Total = array_sum(explode(' ',$Numbers)); ?> </pre> Quote Link to comment Share on other sites More sharing options...
UpcomingPhpDev Posted August 14, 2008 Author Share Posted August 14, 2008 $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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.