calmchess Posted January 15, 2010 Share Posted January 15, 2010 I have an array with numbers in each data slot. How do i loop through and add the numbers in each slot up so i can get the total for the numbers? Link to comment https://forums.phpfreaks.com/topic/188594-add-up-values-from-array/ Share on other sites More sharing options...
Buddski Posted January 15, 2010 Share Posted January 15, 2010 array_sum() perhaps? Link to comment https://forums.phpfreaks.com/topic/188594-add-up-values-from-array/#findComment-995692 Share on other sites More sharing options...
wildteen88 Posted January 15, 2010 Share Posted January 15, 2010 You can use array_sum, or with a foreach loop $total = 0; foreach($myArray as $value) { $total += $value; } echo $value; Link to comment https://forums.phpfreaks.com/topic/188594-add-up-values-from-array/#findComment-995693 Share on other sites More sharing options...
calmchess Posted January 15, 2010 Author Share Posted January 15, 2010 well that was easy i should google search more. Link to comment https://forums.phpfreaks.com/topic/188594-add-up-values-from-array/#findComment-995695 Share on other sites More sharing options...
Buddski Posted January 15, 2010 Share Posted January 15, 2010 The best thing to do if you want to find out simple things like this is goto php.net and use the function search and just type in a few words that outline what you are attempting to do.. "sum array" for instance and the site will give you a list of possible things you might want.. Then pick one that looks good and have a read.. Its all learning.. Link to comment https://forums.phpfreaks.com/topic/188594-add-up-values-from-array/#findComment-995696 Share on other sites More sharing options...
KevinM1 Posted January 15, 2010 Share Posted January 15, 2010 Or, have the following link bookmarked: http://www.php.net/quickref.php Link to comment https://forums.phpfreaks.com/topic/188594-add-up-values-from-array/#findComment-995706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.