willpower Posted February 16, 2007 Share Posted February 16, 2007 Hi Im dealing with UK postcodes I need to check the first to chars in a $string against vars contained in an array. ie $postcode= "M23 4EF" $Array_to Check = ('SW','NW','SF') Not sure what is the best way to do this... Just need to check if 1st chars in $postcode contain any of $Array_to_check and return tru/false/ Thanks Will Link to comment https://forums.phpfreaks.com/topic/38762-solved-haystack-needle/ Share on other sites More sharing options...
ToonMariner Posted February 16, 2007 Share Posted February 16, 2007 <?php function makeRegEX(&$item, $key) { $item = '/^' . $item . '/'; } $postcode= "M23 4EF" $arr = ('SW','NW','SF'); array_walk($arr, 'makeRegEx'); if (preg_match($arr,$postcode)) { echo "Found"; } Link to comment https://forums.phpfreaks.com/topic/38762-solved-haystack-needle/#findComment-186243 Share on other sites More sharing options...
willpower Posted February 16, 2007 Author Share Posted February 16, 2007 top one matey...thanks Link to comment https://forums.phpfreaks.com/topic/38762-solved-haystack-needle/#findComment-186256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.