How can I count the number of element inside an array with value equals a constant? example,
$myArray = array("Kyle","Ben","Sue","Phil","Ben","Mary","Sue","Ben");
how can I directly know how many "Ben" is inside?
|
|
|||
|
Use |
|||||||||||
|
|
|||
|
try the array_count_values() function
output:
|
|||
|
You can do this with array_keys and count.
Output:
|
|||
|
Try the PHP function |
||||
|