note 34844 added to function.array-count-values
| From: | corto at maichiuso dot com | Date: | Fri, 08 Aug 2003 11:27:04 +0000 |
| Subject: | note 34844 added to function.array-count-values | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53637@lists.php.net to get a copy of this message | ||
my solution for count on multidimentional arrays.
<?
/*count all occurrences of field in a multidimensional array */
function total_count_array ()
{
$args = func_get_args();
$marray = array_shift($args);
foreach ($marray as $marray_item) {
for ($i = 0; $i<count($args); $i++) { $group_array[$args[$i]][$marray_item[$args[$i]]] +=1;}
}
return $group_array;
}
/*
Example
$total_count_array = total_count_array ($array, 'uno', 'due');
INPUT $array
Array
(
[0] => Array
(
[uno] => x
[due] => y
)
[1] => Array
(
[uno] => a
[due] => y
)
)
OUTPUT $total_count_array
Array
(
[uno] => Array
(
[x] => 1
[a] => 1
)
[due] => Array
(
[y] => 2
)
)
*/
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-count-values.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34844
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34844&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34844&report=yes