计算foreach循环中的重复条目

时间:2015-06-11 06:30:53

标签: php foreach

我需要在发布数组后找到并计算重复值

foreach ($_POST["marks"] as $marks => $value) {

need to display duplicate values and their count here

}

请帮助

1 个答案:

答案 0 :(得分:-1)

http://us2.php.net/manual/en/function.array-count-values.php

<?php
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
?>

输出

Array
(
    [1] => 2
    [hello] => 2
    [world] => 1
)