What I am doing wrong with the following code? I want to compare if the element $my_id is present within the array $arr. If it is present return TRUE else return FALSE.
for($i=0;$i<$cnt;$i++)
{
if($arr[$i] == $my_id)
{
return TRUE;
}
else
{
return FALSE;
}
}
You could replace that with…
…assuming you don’t really want to return
FALSEif the first element does not match.If that is actually what you wanted, you could use…
If you want to leave your code mostly intact, just move the
return FALSEto outside of the loop body.