Rapture Posted October 10, 2008 Share Posted October 10, 2008 I need a function that checks to see if a particular array contains a particular variable. While I could easily make one using a loop it seems like the kind of thing there would be a built-in function for. Am I right? And what is it? And sorry for the newb question. ; Link to comment https://forums.phpfreaks.com/topic/127819-solved-newb-question-is-there-a-built-in-function-for-this/ Share on other sites More sharing options...
Guest Posted October 10, 2008 Share Posted October 10, 2008 Well if you're looking to see if a value is in an array, there's in_array(mixed $needle, array $haystack) (http://ca.php.net/in_array). Hope that helps. Example: if( in_array('Billy Bob', $customers) ) { ... } Link to comment https://forums.phpfreaks.com/topic/127819-solved-newb-question-is-there-a-built-in-function-for-this/#findComment-661721 Share on other sites More sharing options...
JasonLewis Posted October 10, 2008 Share Posted October 10, 2008 Yes, in_array() is a good one. Some other Array searching functions are: array_search() (similar to in_array() except this returns the key of the found value.) array_key_exists() Link to comment https://forums.phpfreaks.com/topic/127819-solved-newb-question-is-there-a-built-in-function-for-this/#findComment-661723 Share on other sites More sharing options...
Rapture Posted October 10, 2008 Author Share Posted October 10, 2008 Knew it had to exist. Thanks so much! Link to comment https://forums.phpfreaks.com/topic/127819-solved-newb-question-is-there-a-built-in-function-for-this/#findComment-661734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.