I want a PHP program to tell if an array contains any equal data. For that I'm writing this code but it always returns false, even though I have given equal values at position array position 1 and 2. Can anyone help me find out what is wrong with this code?
$a[0]=qwe;
$a[1]=abc;
$a[2]=abc;
$a[3]=xyz;
if(is_equal($a))
{
echo "True";
}
else
{
echo "False";
}
function is_equal($a)
{
$size=sizeof($a);
for ($i = 0; $i <= $size-2; $i++)
{
if ($a[i] === $a[i+1])
{
return true;
}
}
return false;
}
count($a), notsizeof($a), I think. Are you not missing some quotes in the first four lines?sizeofis an alias ofcount;)