note 34844 deleted from function.array-count-values by aidan

From: Date: Sun, 03 Oct 2004 08:33:33 +0000
Subject: note 34844 deleted from function.array-count-values by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77782@lists.php.net to get a copy of this message
Note Submitter: corto at maichiuso dot com ---- 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 ) ) */ ?>

« previous php.notes (#77782) next »