StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 Hey all. Normally I would find something out like this myself but I am mentally exhausted after coding 3000 lines of code today. So I was wondering if anyone knows a way to count unique array elements? For example I have an array of 144 elements, some of them will be family1, some will be family2, family3, family4, or none. How to I count how many are family1? I am trying to determine who has the most amount of territories in an array. Quote Link to comment https://forums.phpfreaks.com/topic/51255-count-unique-array-elements/ Share on other sites More sharing options...
Psycho Posted May 14, 2007 Share Posted May 14, 2007 So, this is a multidimensional array? Can you show the format of the array? A possible solution would be to use array_keys() with the optional search parameter. Basically use array_keys to return an array of all the keys that hold the search value. Then count the number of elements in the returned array. Quote Link to comment https://forums.phpfreaks.com/topic/51255-count-unique-array-elements/#findComment-252499 Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Author Share Posted May 14, 2007 I figured it out, array_count_values is my friend this go around. Quote Link to comment https://forums.phpfreaks.com/topic/51255-count-unique-array-elements/#findComment-252501 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.