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 Quote 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. Quote 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. Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/158270-array/#findComment-834753 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.