note 29081 added to function.in-array

From: Date: Sat, 01 Feb 2003 10:48:48 +0000
Subject: note 29081 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-43254@lists.php.net to get a copy of this message
With in_array() you need to specify the exact value held in an array element for a successful match. I needed a function where I could see if only part of an array element matched so I wrote this function to do it, it also searches keys of the array if required (only useful for associative arrays). This function is for use with strings: function inarray($needle, $array, $searchKey = false) { if ($searchKey) { foreach ($array as $key => $value) if (stristr($key, $needle)) { return true; } } } else { foreach ($array as $value) if (stristr($value, $needle)) { return true; } } } return false; } -- http://www.php.net/manual/en/function.in-array.php http://master.php.net/manage/user-notes.php?action=edit+29081 http://master.php.net/manage/user-notes.php?action=delete+29081 http://master.php.net/manage/user-notes.php?action=reject+29081

« previous php.notes (#43254) next »