php - Find a value in an array -
what doing wrong following code? want compare if element $my_id
present within array $arr
. if present return true
else return false
.
for($i=0;$i<$cnt;$i++) { if($arr[$i] == $my_id) { return true; } else { return false; } }
you replace with...
return in_array($my_id, $arr);
...assuming don't want return false
if first element not match.
if wanted, use...
return $arr[0] == $my_id;
if want leave code intact, move return false
outside of loop body.
Comments
Post a Comment