Michdd Posted November 18, 2008 Share Posted November 18, 2008 I know it's using a foreach() statement, but how would I go about adding the contents of an array to get a total. Example: $number[0] = "1"; $number[3] = "5"; I want it to add all the numbers within a certain array to get total. Link to comment https://forums.phpfreaks.com/topic/133148-simple-question-how-do-i-add-the-contents-of-an-array/ Share on other sites More sharing options...
xtopolis Posted November 18, 2008 Share Posted November 18, 2008 Actually, there is a php function for summing values in an array, coincidentally named "array_sum" <?php $a = array(2, 4, 6, ; echo "sum(a) = " . array_sum($a); ?> (from http://us2.php.net/array_sum) Link to comment https://forums.phpfreaks.com/topic/133148-simple-question-how-do-i-add-the-contents-of-an-array/#findComment-692486 Share on other sites More sharing options...
DarkWater Posted November 18, 2008 Share Posted November 18, 2008 array_sum() Link to comment https://forums.phpfreaks.com/topic/133148-simple-question-how-do-i-add-the-contents-of-an-array/#findComment-692487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.