This is my first post on blogger and I am going to write this blog for PHP interview question.
1) How can we get the count of each value in PHP array?
Ans: array_count_values($array);
2) Print top 5 values from an array order by count in reverse order.
Ans :
Live Codepad Example
I will add more question here when I get new questions. :)
Thanks
1) How can we get the count of each value in PHP array?
Ans: array_count_values($array);
2) Print top 5 values from an array order by count in reverse order.
Ans :
<?php
echo "<pre>";
$str = "my name is yogesh, i am great yogesh, and i am great programmer too.";
$new_arr = array_filter(preg_split('/[,. ]/',$str));
$count = array_count_values($new_arr);
arsort($count);
$sliced = array_slice($count,0,5,true);
print_r($sliced);
Live Codepad Example
I will add more question here when I get new questions. :)
Thanks