PHP 统计二维数组某个值有几个?
PHP 计算二维数组某个值出现的次数
$list = [
['id' => 1, 'userId' => 5],
['id' => 2, 'userId' => 5],
['id' => 3, 'userId' => 6],
];
$userId = 5;
$arr=array_column($list,'userId');//把值提取出来转成一维数组
$arr=array_count_values($arr);//数组的值作为键名,该值在数组中出现的次数作为值
echo $arr[$userId];//结果2