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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -