$type_count = 0;
foreach($arr as $v) {
    if(array_key_exists('type', $v)) $type_count++;
}
Answer from Amber on Stack Overflow
🌐
PHP
php.net › manual › en › function.array-count-values.php
PHP: array_count_values - Manual
... Simple way to find number of ... 'userId' => 5], ['id' => 3, 'userId' => 6], ]; $userId = 5; echo array_count_values(array_column($list, 'userId'))[$userId]; // outputs: 2 ?>...
🌐
Stack Overflow
stackoverflow.com › questions › 37925900 › count-multidimensional-array-keys-with-specific-value
php - Count multidimensional array keys with specific value - Stack Overflow
June 21, 2016 - Sign up to request clarification or add additional context in comments. ... Better do ` $count[$array['ruleid']] = isset( $count[$array['ruleid']]) ? $count[$array['ruleid']]+1:1;` first time the key is set to NULL PHP 5.6 -- ignore this !!
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 340233 › count-php-array-values-in-multi-dimension-array
Count php array values in multi dimension ... [SOLVED] | DaniWeb
How you determine it returns true or false is entirely up to you. In my example, i'm using the 'value' parent::current() of the array item to do my comparison. You could also use parent::key() to get the array key.
Find elsewhere
Top answer
1 of 2
1

Create a results array. Then iterate the outer array, and inside the loop iterate the child array and increment the results array accordingly:

$data = array(
    "barack obama"  =>  array(0,50,150,250,600,900,45,150,1050),
    "tom jones"     =>  array(80,120,150,75,250,80,1100,1900),
    "bob mugabe"    =>  array(50,120,10,0,250,900,600,45,1000,1010),
);    

$results = array(); // create an empty array to store our results
foreach ( $data as $item ): // loop the outer array
    foreach ( $item as $key => $value ): // loop the inner array
        if ( array_key_exists($value,$results) ){ // check if value is already in results, if not set to 1, otherwise increment
            $results[$value] = $results[$value] + 1;
        } else { 
            $results[$value] = 1;
        }

    endforeach;
endforeach;

// show our results array
print "<pre>";
print_r($results);
2 of 2
0

Iterate over the multi-dimensional array like this:

<?php
$data = array(
    'barack_obama' => array('19', '92', '27', '55', '57', '1409', '1384', '1362', '1345', '1280'),
    'united_states' => array('72', '81', '89', '90', '92', '21', '23', '27', '32', '47', '55'),
);

$aggregator = [];
foreach (array_keys($data) as $i) {
    for ($j = 0, $entryCount = count($data[$i]); $j < $entryCount; $j++) {
        $index = $data[$i][$j];
        $aggregator[$index] = isset($aggregator[$index]) ? $aggregator[$index] + 1 : 1;
    }
}
var_export($aggregator);

The result:

array ( 19 => 1, 92 => 2, 27 => 2, 55 => 2, 57 => 1, 1409 => 1, 1384 => 1, 1362 => 1, 1345 => 1, 1280 => 1, 72 => 1, 81 => 1, 89 => 1, 90 => 1, 21 => 1, 23 => 1, 32 => 1, 47 => 1, )
🌐
Matt Doyle
elated.com › home › blog › counting php array elements using count()
Counting PHP Array Elements Using count()
July 23, 2022 - PHP makes it easy to count array elements, thanks to its built-in count() function. In this tutorial you’ll learn how to use count() to count the elements in both regular and multidimensional arrays, and how to move through all the elements ...
🌐
Stack Overflow
stackoverflow.com › questions › 58111484 › how-to-count-specific-key-values-from-a-multi-dimensional-array
php - How to count specific key values from a multi-dimensional array? - Stack Overflow
September 26, 2019 - function take_types($array){ foreach ($array as $key => $value) { $types[] = $value['type']; if(!empty($value['children'])){ $this->take_types($value['children']); } } return $types; } When I use the above function the output is like this: ... ...
🌐
Wordpress
vijaymrami.wordpress.com › 2016 › 02 › 03 › count-array-key-values-with-array_count_values-count-and-sizeof-php-functions
Count array key values with array_count_values, count and sizeof PHP functions – PHP Website Development
February 5, 2016 - Returns an associative array of values from array as keys and their count as value. <?php $array = array(1, "hello", 1, "world", "hello"); echo "<pre>"; print_r(array_count_values($array)); echo "</pre>"; ?>