array_count_values
갈 수있는 가장 쉬운 방법이지만, 경우에 당신은 당신이 찾고있는 무엇을 수행하는 방법을 파악해야 사용, 여기에 자세한 버전입니다.
$input = array(1, 2, 3, 4, 1);
$unique = array_unique($input);
// If $input and $unique are different in length,
// there is one or more repeating values
if (count($input) !== count($unique)) {
$repeat = array();
// Sort values in order to have equal values next to each other
sort($input);
for ($i = 1; $i < count($input) - 1; $i++) {
// If two adjacent numbers are equal, that's a repeating number.
// Add that to the pile of repeated input, disregarding (at this stage)
// whether it is there already for simplicity.
if ($input[$i] === $input[$i - 1]) {
$repeat[] = $input[$i];
}
}
// Finally filter out any duplicates from the repeated values
$repeat = array_unique($repeat);
echo implode(', ', $repeat);
} else {
// All unique, display all
echo implode(', ', $input);
}
간결한 한 줄 틱 버전은 다음과 같습니다 내 질문에 실수가
$input = array(1, 2, 3, 4, 1);
$repeat = array_keys(
array_filter(
array_count_values($input),
function ($freq) { return $freq > 1; }
)
);
echo count($repeat) > 0
? implode(', ', $repeat)
: implode(', ', $input);
Hoppa 좋잖은, 미안, 대신 URL의 URL에서 의미하고, 당신이 나를 도울 수 암호? pleasecan 당신이 날 도와 줘, 매우 중요합니다. – UGD
글쎄, 최소한 샘플 URL을 제공해야 할 것입니다. – hoppa
이것은 전체 코드입니다 * 수정했습니다 ...)하지만 작동하지 않습니다 ... – UGD