PHP Count words in array -


this question has answer here:

ok, in case have array kinda (but larger)

$array = [     0 => "tod",     1 => "tod",     2 => "max",     3 => "jeff",     4 => "tod",     5 => "max",     6 => "jeff",     7 => "max",     8 => "max" ]; 

now question is, there way count how many occurences of tod,jeff & maxthere in array $array , store them seperate variables, example desired outcome there 3 seperate variables these there values (based off of sample code shown above)

$todamount = 3; $jeffamount = 2; $maxamount = 4; 

i've done quite bit of research , havn't found out way :/
thanks reading!

array_count_values() need.

<?php  $array = [     0 => "tod",     1 => "tod",     2 => "max",     3 => "jeff",     4 => "tod",     5 => "max",     6 => "jef",     7 => "max",     8 => "max" ];     print_r(array_count_values($array)); ?> 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -