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
& max
there 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
Post a Comment