dsaba Posted September 23, 2007 Share Posted September 23, 2007 $array = array('hellohowareyoudoingtoday', 'helo'); $findLo = array_search('lo', $array); if ($findLo == FALSE) { echo 'did not find it! uh oh!'; } This returns "did not find it!' Is there a better way to search inside of arrays to imitate strstr() ?? Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 23, 2007 Share Posted September 23, 2007 http://uk3.php.net/manual/en/function.preg-grep.php Quote Link to comment Share on other sites More sharing options...
dbo Posted September 23, 2007 Share Posted September 23, 2007 What are you trying to do exactly? Would you want an array returned of all tokens that contained a match when running strstr over it? Quote Link to comment Share on other sites More sharing options...
teng84 Posted September 23, 2007 Share Posted September 23, 2007 the way you do it array search will always fail, you have to explode it or divide those character Quote Link to comment Share on other sites More sharing options...
dsaba Posted September 23, 2007 Author Share Posted September 23, 2007 function find_needle_inArray($array, $needle) { foreach ($array as $v) { $findIt = strstr($v, $needle); if ($findIt == FALSE) { $boolean = 'set'; break; } if (!isset($boolean)) { return TRUE; } else { return FALSE; } would this be faster than that regex function? } Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 23, 2007 Share Posted September 23, 2007 http://php.net/in_array Quote Link to comment Share on other sites More sharing options...
teng84 Posted September 23, 2007 Share Posted September 23, 2007 http://php.net/in_array ?????? Quote Link to comment Share on other sites More sharing options...
dsaba Posted September 23, 2007 Author Share Posted September 23, 2007 guru VS. proficient proficient wins! what were you thinking jesirose? lol Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 23, 2007 Share Posted September 23, 2007 http://php.net/in_array ?????? omg I can use smilies too. Check it out. :D :D :o :o ;D ;D After rereading the OP, I think you would have to write your own function that would loop through the array and use strstr(). Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 23, 2007 Share Posted September 23, 2007 $a = array('hellohowareyoudoingtoday', 'helo'); $c=preg_grep("/lo/",$a); if ($c == FALSE) { echo 'did not find it! uh oh!'."<br>"; } else { echo "did: "."<br>"; foreach($c as $e) { echo "pos: ".$e."<br>"; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.