note 95718 added to function.array-count-values

From: Date: Mon, 18 Jan 2010 11:36:14 +0000
Subject: note 95718 added to function.array-count-values
Groups: php.notes 
Request: Send a blank email to php-notes+get-165063@lists.php.net to get a copy of this message
Sorry for my Previous Version right below, here`s the right (without echo" ".) Possible with one or multiple Array <?php $ar1[] = array("red","green","yellow","blue"); $ar1[] = array("green","yellow","brown","red","white","yellow"); $ar1[] = array("red","green","brown","blue","black","yellow"); #$ar1= array("red","green","brown","blue","black","red","green"); // Possible with one or multiple Array $res = array_icount_values ($ar1); print_r($res); function array_icount_values($arr,$lower=true) { $arr2=array(); if(!is_array($arr['0'])){$arr=array($arr);} foreach($arr as $k=> $v){ foreach($v as $v2){ if($lower==true) {$v2=strtolower($v2);} if(!isset($arr2[$v2])){ $arr2[$v2]=1; }else{ $arr2[$v2]++; } } } return $arr2; } /* Will print: Array ( [red] => 3 [green] => 3 [yellow] => 4 [blue] => 2 [brown] => 2 [white] => 1 [black] => 1 ) */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 78.52.166.171 ---- Manual Page -- http://www.php.net/manual/en/function.array-count-values.php Edit -- https://master.php.net/note/edit/95718 Del: integrated -- https://master.php.net/note/delete/95718/integrated Del: useless -- https://master.php.net/note/delete/95718/useless Del: bad code -- https://master.php.net/note/delete/95718/bad+code Del: spam -- https://master.php.net/note/delete/95718/spam Del: non-english -- https://master.php.net/note/delete/95718/non-english Del: in docs -- https://master.php.net/note/delete/95718/in+docs Del: other reasons-- https://master.php.net/note/delete/95718 Reject -- https://master.php.net/note/reject/95718 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165063) next »