a L p Posted August 31, 2009 Share Posted August 31, 2009 Hello, I am have a newbie question... I have an array that lists specific countries, and I want to have an if statement that that checks to see if a variable set by the user is in that array: if $variable is in $array then { do this } it seems like this has to be something easy... anyone able to point me in the right direction? Thanks, Andy Quote Link to comment https://forums.phpfreaks.com/topic/172595-solved-how-to-check-if-a-variable-is-in-an-array/ Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 yep, its called in_array if (in_array($needle, $haystack)){ //do something } with needle being your variable and haystack being your array Quote Link to comment https://forums.phpfreaks.com/topic/172595-solved-how-to-check-if-a-variable-is-in-an-array/#findComment-909830 Share on other sites More sharing options...
a L p Posted August 31, 2009 Author Share Posted August 31, 2009 Perfect! thank you Quote Link to comment https://forums.phpfreaks.com/topic/172595-solved-how-to-check-if-a-variable-is-in-an-array/#findComment-909848 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.