php - How to count number of the same elements in array -


I have a very simple problem. I have an array

  $ a = array ('Dog', 'dog', 'dog', 'mouse', 'mouse', 'mouse', 'cat', 'cat');  

How many counts are there are elements called 'dogs'? I tried the count () function, I know that this is not good because the count does not appear array only calculates the number of elements

for example my problem The answer will be:

  dog = 3 mouse = 3 cat = 2  

Use:

  print_r (array_count_values ​​($ a)); Array ([dog] => 3 [mouse] => 3 [cat] => 2) $ count = array_count_values ​​($ a); Echo $ count ['dog']; // print3  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -