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) Link to comment https://forums.phpfreaks.com/topic/79950-choose-a-value-in-array/ 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 Link to comment https://forums.phpfreaks.com/topic/79950-choose-a-value-in-array/#findComment-404967 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]); ?> Link to comment https://forums.phpfreaks.com/topic/79950-choose-a-value-in-array/#findComment-404981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.