Full-Demon Posted June 10, 2007 Share Posted June 10, 2007 Hi, I have another array problem: I use array_search in my code. But what if it finds the needle on the first key/value of the array? It will output zero, so how do I know the difference between 'not found' and 'found on the first key'? As both will result in zero. I use this, which is not workin: $result= array_search($needle, $array); if ($result !== 0) { ... I use the triple '=' (but than in the form of which it has a leading '!'). How can I know for sure its on the first key instead of not found? Thanks in advance Full-D Link to comment https://forums.phpfreaks.com/topic/54994-array_search-what-if-the-needle-is-found-on-key-0/ Share on other sites More sharing options...
Hypnos Posted June 10, 2007 Share Posted June 10, 2007 if(array_search($needle, $array) === FALSE) { echo 'Not found.'; } else { echo 'Found.'; } Link to comment https://forums.phpfreaks.com/topic/54994-array_search-what-if-the-needle-is-found-on-key-0/#findComment-271895 Share on other sites More sharing options...
Full-Demon Posted June 10, 2007 Author Share Posted June 10, 2007 Thank you! Working perfect Full-D Link to comment https://forums.phpfreaks.com/topic/54994-array_search-what-if-the-needle-is-found-on-key-0/#findComment-271957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.