Finding item of the array which is represented more than once
<?php

var_dump(containsDuplicate([1,1,2,5,3]));
var_dump(containsduplicate([2,7,7,6,9,0,0]));
var_dump(containsDuplicate([1,4,5,0,7]));
//Using array_count_values
function containsDuplicate($array){
	$counted=array_count_values($array);
	return max($counted)>1;
}
//Using foreach loop
function containsDuplicate_2($array){
	$values=[];
	
	foreach ($array as $item){
		if (array_count_values($array)>1){
			return true;
		}
	}
	return false;
}
//both works well !!
by ვაჟა ტყემალაძე
2 years ago
Problem Solving
php
0
Pro tip: use ```triple backticks around text``` to write in code fences