Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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 比较输入并计数重复项?_Php_Html - Fatal编程技术网

Php 比较输入并计数重复项?

Php 比较输入并计数重复项?,php,html,Php,Html,我有一个表格,要求最多20个1-4个字符的代码。我想做的是得到每段代码的计数,这样我就可以得到如下输出 AB //entered once EFOO //entered once AACC x 2 //because AACC was entered twice into form DDFE x 6 //because DDFE was entered into the form 6 times 下面是一个我的代码的例子,我得到了所有的结果,我只是不知道如何比较和计算它们 <input

我有一个表格,要求最多20个1-4个字符的代码。我想做的是得到每段代码的计数,这样我就可以得到如下输出

AB //entered once
EFOO //entered once
AACC x 2 //because AACC was entered twice into form
DDFE x 6 //because DDFE was entered into the form 6 times
下面是一个我的代码的例子,我得到了所有的结果,我只是不知道如何比较和计算它们

<input type="text" name="code[]">

foreach ($_POST as $key=>$val) {
   echo $_POST['code'][$key];
}

foreach($\发布为$key=>$val){
echo$_POST['code'][$key];
}
哈希表

foreach ($_POST as $key=>$val) {
    $counter[$val] ++;
}
现在,
$counter
具有作为输入的键(即AACC),以及它们出现多少次的值。

哈希表

foreach ($_POST as $key=>$val) {
    $counter[$val] ++;
}

现在,
$counter
具有作为输入的键(即AACC),以及它们出现多少次的值。

尽管@PaulProgrammer的答案是正确的,但php有一个内置函数:

因此,在您的情况下,您可以:

$frequencies = array_count_values($_POST);

尽管@PaulProgrammer的答案是正确的,但php有一个内置函数:

因此,在您的情况下,您可以:

$frequencies = array_count_values($_POST);