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

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -