Entry
How can I determine if an array contains a value?
What is the in_array() function for?
Jan 28th, 2000 00:28
Nathan Wallace, Radek Vybiral, Mark Roedel
In many cases I need in_array() function, which returns true or false if
an element is in the array.
Here is the in_array function from PHP4:
http://www.php.net/manual/html/function.in-array.html
On PHP3, try using this code:
function in_array($item, $my_array) {
$found = 0; // Not found
while (list($val) = each($my_array)) {
if ($item == $my_array[$val]) { $found = 1; }
}
return $found;
}