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. Link to comment https://forums.phpfreaks.com/topic/119733-solved-adding-value-of-array-value-value/ Share on other sites More sharing options...
Jabop Posted August 14, 2008 Share Posted August 14, 2008 $TotalNumbers+=$Value Link to comment https://forums.phpfreaks.com/topic/119733-solved-adding-value-of-array-value-value/#findComment-616870 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> Link to comment https://forums.phpfreaks.com/topic/119733-solved-adding-value-of-array-value-value/#findComment-616872 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 Link to comment https://forums.phpfreaks.com/topic/119733-solved-adding-value-of-array-value-value/#findComment-616878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.