askshinde Posted April 9, 2009 Share Posted April 9, 2009 $websites = array(0 => 'qu',1 => 'he',2 => 'ra',3 => 'ac',4 => 'fr',5 => 'frs',6 => 'go',7 => 'wr',8 => 'lo'); $wID = array('Q','H','R','A','F','F2','G','W','L'); $position = array_search($reffDOM,$websites); $key = $wID[$position]; where $reffDOM is user input. Issue : Even if value exists in array the array_search results 0 or '' or false Quote Link to comment https://forums.phpfreaks.com/topic/153280-array_search-bug/ Share on other sites More sharing options...
sKunKbad Posted April 9, 2009 Share Posted April 9, 2009 This returns 3, so I don't know what is the problem? <?php $websites = array(0 => 'qu',1 => 'he',2 => 'ra',3 => 'ac',4 => 'fr',5 => 'frs',6 => 'go',7 => 'wr',8 => 'lo'); $position = array_search('ac',$websites); echo $position; ?> Quote Link to comment https://forums.phpfreaks.com/topic/153280-array_search-bug/#findComment-805264 Share on other sites More sharing options...
sKunKbad Posted April 9, 2009 Share Posted April 9, 2009 A full example for your pleasure: <?php $reffDOM = 'lo'; // here is your "user input" $websites = array(0 => 'qu',1 => 'he',2 => 'ra',3 => 'ac',4 => 'fr',5 => 'frs',6 => 'go',7 => 'wr',8 => 'lo'); $wID = array('Q','H','R','A','F','F2','G','W','L'); $position = array_search($reffDOM,$websites); $key = $wID[$position]; echo $key; ?> Quote Link to comment https://forums.phpfreaks.com/topic/153280-array_search-bug/#findComment-805267 Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2009 Share Posted April 9, 2009 Did you check what your actual input is in $reffDOM that did not work? Quote Link to comment https://forums.phpfreaks.com/topic/153280-array_search-bug/#findComment-805271 Share on other sites More sharing options...
Mark Baker Posted April 9, 2009 Share Posted April 9, 2009 Array search can return a valid 0 value, so you need to distinguish whether the return is a 0 or a boolean false $position = array_search($reffDOM,$websites); if ($position === false) echo 'Not found'; } Quote Link to comment https://forums.phpfreaks.com/topic/153280-array_search-bug/#findComment-805338 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.