FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Count how many times a value occurs in an array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Count how many times a value occurs in an array [message #179264 is a reply to message #179263] Thu, 27 September 2012 07:10 Go to previous messageGo to previous message
aroniss is currently offline  aroniss
Messages: 1
Registered: September 2012
Karma:
Junior Member
On Thursday, September 27, 2012 8:25:21 AM UTC+2, Ryan wrote:
> I have an array lets say for example:
>
>
>
> $my_array = array('1', '1', '2', '3', '1', '3', '2');
>
>
>
> I want a listing of each value in the array and how many times it occurs for in this case it would look like this
>
>
>
> array ('1' => 3, '2' => 2, '3' => 2)
>
>
>
> jw if ph has a build in function to make this easy of am I going to have to roll my own by looping though the array?

Use built-in function: array_count_values($my_array)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Only Allow exec in CLI
Next Topic: Re: FEDEX Shipping
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 09:43:41 GMT 2024

Total time taken to generate the page: 0.03820 seconds