sql server - Count number of occurrences of value in a PHP array -
i have loaded results of sql query array. fields computername, timeindays, room, keyed on computername.
i find out how many times each timeindays occurrence happens.
example values of array is:
[stu-czc1087snc] => array ( [computername] => stu-czc1087snc [time_in_days] => 0 [room] => 4q08 ) [stu-czc02501qt] => array ( [computername] => stu-czc02501qt [time_in_days] => 12 [room] => 2r017 )
so want know how many computers have time_in_days = 12, , how many have time_in_days = 0 example. used plot graph.
how do / best way of doing this?
try this, $input array of arrays computer data:
$result = array(); foreach($input $computername => $arr){ if(!isset($result[ $arr['time_in_days'] ])) $result[ $arr['time_in_days'] ] = 0; $result[ $arr['time_in_days'] ]++; } return $result;
the result like:
[ 12 => 2, //2 computers have time_in_days of 12 0 => 1 //1 computer has time_in_days of 0 ]
Comments
Post a Comment