Sam San
Sam San

Reputation: 6903

Counting arrays in loop

I have a loop...

while($rows=mysql_fetch_array($result))
    {

        $staff[] = $rows['staff'];
        $a = array_count_values($staff);
        $b = count($a);
        echo"$b<br>";

    }

that output

1
1
1
2
2
2
3
3
4
5
5

on my research, it must be and I wanted the result to be this way

3   (is equal to three 1's)
3   (is equal to three 2's)
2   (is equal to two 3)
1   (is equal to one 4)
2   (is equal to two 5's)

any help?

what I want is to get the number of same element in an array

Upvotes: -2

Views: 105

Answers (1)

Bugs
Bugs

Reputation: 1452

As far as I understand your concern, this should do the trick:

$staff = array();
while($rows=mysql_fetch_array($result))
{
    $staff[] = $rows['staff'];
}
$a = array_count_values($staff);
print_r($a);

Upvotes: 1

Related Questions