note 120474 deleted from function.array-count-values by crell
| From: | crell@php.net | Date: | Tue, 12 Apr 2022 01:03:20 +0000 |
| Subject: | note 120474 deleted from function.array-count-values by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218171@lists.php.net to get a copy of this message | ||
Note Submitter: jekkilekki at gmail dot com
----
Simple example to count the values of a $key in an associative array:
/**
* Associative Array Count Values
*
* Returns an array containing the number of values for a given $key in a given associative $array
*
* @param array $array The associative array to count values for
* @param String $key The key to count values for
* @return array A new array containing the counted values for the key in the original associative
array
*/
function assc_array_count_values( $array, $key ) {
foreach( $array as $row ) {
$new_array[] = $row[$key];
}
return array_count_values( $new_array );
}