0

代码

$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);

结果是

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,请帮帮我......

4

1 回答 1

0

因为$array是一个包含另一个数组的数组(我假设你想要分组),那么试试这个:

print_r(array_count_values($array[0]));
于 2013-03-27T04:33:46.767 回答