common Posted May 15, 2009 Share Posted May 15, 2009 Hey I have an array where the keys are words in a string and the value of the array is amount of times each word comes up in the string. I want to count all the values(which are numbers). Can anyone tell me how i can do that?? Thanks Link to comment https://forums.phpfreaks.com/topic/158270-array/ Share on other sites More sharing options...
Ken2k7 Posted May 15, 2009 Share Posted May 15, 2009 Loop through the array and add them all up. Link to comment https://forums.phpfreaks.com/topic/158270-array/#findComment-834746 Share on other sites More sharing options...
Maq Posted May 15, 2009 Share Posted May 15, 2009 Loop through the array and add them all up. Or, use array_sum. Link to comment https://forums.phpfreaks.com/topic/158270-array/#findComment-834748 Share on other sites More sharing options...
Ken2k7 Posted May 15, 2009 Share Posted May 15, 2009 Loop through the array and add them all up. Or, use array_sum. I did not know that one. Thanks for the heads up Maq. Link to comment https://forums.phpfreaks.com/topic/158270-array/#findComment-834750 Share on other sites More sharing options...
Maq Posted May 15, 2009 Share Posted May 15, 2009 Loop through the array and add them all up. Or, use array_sum. I did not know that one. Thanks for the heads up Maq. The function itself probably does what you suggested, loops through and adds the element values. But there's no need to write it yourself. Link to comment https://forums.phpfreaks.com/topic/158270-array/#findComment-834753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.