Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check how many times specific value in array PHP [duplicate]

Tags:

arrays

php

count

I have an array named $uid. How can I check to see how many times the value "12" is in my $uid array?

like image 817
DobotJr Avatar asked Oct 31 '11 22:10

DobotJr


1 Answers

Several ways.

$cnt = count(array_filter($uid,function($a) {return $a==12;}));

or

$tmp = array_count_values($uid);
$cnt = $tmp[12];

or any number of other methods.

like image 196
Niet the Dark Absol Avatar answered Oct 06 '22 08:10

Niet the Dark Absol