Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php计算while循环中的重复值_Php_Count - Fatal编程技术网

如何使用php计算while循环中的重复值

如何使用php计算while循环中的重复值,php,count,Php,Count,$query=“选择*表格项目” $result=mysql\u query($query) 如果可能,示例输出应该是这样的内部while循环 第一项2 第二项3 第五项4您可以使用sql而不需要php SELECT COUNT(*) as N,item FROM tableitem GROUP BY item 它将返回重复的项目,您可以使用n>1进行检查。您可以为组添加更多列 $itemArray; while ($row = mysql_fetch_array($result)){

$query=“选择*表格项目”
$result=mysql\u query($query)

如果可能,示例输出应该是这样的内部while循环

第一项2
第二项3

第五项4

您可以使用sql而不需要php

SELECT COUNT(*) as N,item 
FROM tableitem
GROUP BY item
它将返回重复的项目,您可以使用
n>1
进行检查。您可以为组添加更多列

$itemArray;
while ($row = mysql_fetch_array($result)){
    if($row['n']>1){
       itemArray[] = $row['item'];    
    }    
}
print_r($itemArray);

如果使用尝试计数的键递增数组值:

$check = array();
foreach($values as $key => $value) {
   if (isset($check[$key])) {
       $check[$key]++;
   } else {
       $check[$key]=1;
   }
}
var_dump($check); 

Tnkeyou飓风,但我很抱歉地告诉你,我在循环中有计算。因此,根据计算和条件,这只是我计算物品的时间。thnks nicholas。我正试图根据上面的密码来计算物品的数量
$check = array();
foreach($values as $key => $value) {
   if (isset($check[$key])) {
       $check[$key]++;
   } else {
       $check[$key]=1;
   }
}
var_dump($check);