php count array elements with specific key 1

php count array elements with specific key

$cnt = count(array_filter($array,function($element) {
  return $element['your_key']=='foo';
}));

Here is what the above code is Doing:
1. It’s using array_filter to filter out all the elements that don’t have your_key set to foo.
2. It’s using count to count the number of elements that are left.

Similar Posts