php计数和搜索

时间:2013-03-27 04:23:37

标签: php arrays search count

$array = array($cat2);
print_r(array_count_values($array));

//out
Array ( [YES] => 1 ) Array ( [YES] => 1 ) Array ( [YES] => 1 ) Array ( [YES] => 1 ) Array ( [NO] => 1 ) Array ( [NO] => 1 ) Array ( [YES] => 1 ) Array ( [NO] => 1 ) Array ( [NO] => 1 ) Array ( [YES] => 1 )

多少计数是和否 这是我的代码

$YES = array_search('YES', $array);

$NO = array_search('NO', $array);

结果是YES

Array ( [YES] => 1 ) 0 Array ( [YES] => 1 ) 0 Array ( [YES] => 1 ) 0 Array ( [YES] => 1 ) 0 Array ( [NO] => 1 ) Array ( [NO] => 1 ) Array ( [YES] => 1 ) 0 Array ( [NO] => 1 ) Array ( [NO] => 1 ) Array ( [YES] => 1 ) 0

结果没有

Array ( [YES] => 1 )Array ( [YES] => 1 )Array ( [YES] => 1 )Array ( [YES] => 1 )Array ( [NO] => 1 )Array ( [NO] => 1 )Array ( [YES] => 1 )Array ( [NO] => 1 )Array ( [NO] => 1 )Array ( [YES] => 1 ) 

我有结果

YES = 6
NO = 4
这个没有mysql的php,请帮帮我......

1 个答案:

答案 0 :(得分:0)

由于$array是一个包含另一个数组的数组(我假设你想要分组),所以试试这个:

print_r(array_count_values($array[0]));