How to count values from array in php?
In this post, This function can count all the values of an array in php.
1. Code
<?php function arrayCountValues($array){ $result = array_count_values($array); return $result; } $arr[0] = 'Language'; $arr[1] = 'Laravel'; $arr[2] = 'PHP'; $arr[3] = 'Java'; $arr[4] = 'Language'; print_r(arrayCountValues($arr)); ?>
2. Example:
Input:
$arr[0] = 'Language'; $arr[1] = 'Laravel'; $arr[2] = 'PHP'; $arr[3] = 'Java'; $arr[4] = 'Language';
Output:
Array ( [Language] => 2 [Laravel] => 1 [PHP] => 1 [Java] => 1 )