"Search" code finds ANYTHING

From: Date: Thu, 16 Aug 2001 01:21:39 +0000
Subject: "Search" code finds ANYTHING
Groups: php.general 
Request: Send a blank email to php-general+get-62925@lists.php.net to get a copy of this message
Hi, function search_the_array($array) { global $search_tmp; $result = array_search($search_tmp, $array, TRUE); reset($array); while (!($result === FALSE) && (list($k, $v) = each($array))) { // Or maybe you wanted ereg($search_tmp, $v) here... $result = ereg($v, $search_tmp) ? $k : FALSE; } return ' '.$result; // extra space needed before the "key" } This code immediately returns a result, no matter what I type in there and what the array consists of. I even tried searching "Singapore" for "I will get a result no matter what I search for" and BANG... PHP fires back a result. I didn't write the code myself so I have no idea what's going on there... but I'd be glad if someone could help me. This code is supposed to search an array until it finds "$search_tmp" inside it... TIA, Raphael

« previous php.general (#62925) next »