note 32480 modified in function.array-count-values by vrana

From: Date: Tue, 17 Aug 2004 13:57:20 +0000
Subject: note 32480 modified in function.array-count-values by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79874@lists.php.net to get a copy of this message
I fount a solution for the count of array elements in the sense of array_count_values, but i was not able to use the function array_count_values itself because it does not say me if arrays exists in the given array, so i had to use a foreach loop and a little bit of recursivity ;) <?php function array_count_values_multidim($a,$out=false) { if ($out===false) $out=array(); if (is_array($a)) { foreach($a as $e) $out=array_count_values_multidim($e,$out); } else { if (array_key_exists($a,$out)) $out[$a]++; else $out[$a]=1; } return $out; } ?> --was-- I fount a solution for the count of array elements in the sense of array_count_values, but i was not able to use the function array_count_values itself because it does not say me if arrays exists in the given array, so i had to use a foreach loop and a little bit of recursivity ;) function array_count_values_multidim($a,$out=false) { if ($out===false) $out=array(); if (is_array($a)) { foreach($a as $e) $out=array_count_values_multidim($e,$out); } else { if (array_key_exists($a,$out)) $out[$a]++; else $out[$a]=1; } return $out; } http://php.net/manual/en/function.array-count-values.php

« previous php.notes (#79874) next »