asmith Posted December 3, 2007 Share Posted December 3, 2007 $a = array ("aaa","abc","ddd","aaad,"ggfrd",aaer"); i can find values in that array start with "aa" , with pregmatch and in_array functions. i want to put the value that starts with "aa" in a variable . how can i achive that ? (assuming i don't know the whole of array . i just know there are values starts with "aa" , but don't know the entire value) Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 3, 2007 Share Posted December 3, 2007 Did you read up on preg_match? It will store a match in a variable for you, ready to use. If you want to find all instances, use preg_match_all. PhREEEk Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 consider the following code hopefully it should do for your needs <?php $a = array ("aaa","abc","ddd","aaad","aaaggfrdaaa","aaer"); $strMatch = "aa"; preg_match_all("/(\b{$strMatch}[^\,]+)/i",implode(",",$a),$arrMatches); print_r($arrMatches[1]); ?> Quote Link to comment 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.