PHP: check if an element belongs to an array -
i know php 4 , php 5 supports built in function in_array
determining element in array or not.
but, using prior version of php reason , wanted know alternative it.
use custom function. future compatibility, use function_exists
check if current version of php you're using indeed have in_array
.
function inarray($needle, $haystack) { if (function_exists('in_array')) { return in_array($needle, $haystack); } else { foreach ($haystack $e) { if ($e === $needle) { return true; } } return false; } }
Comments
Post a Comment