Jump to content

choose a value in array


asmith

Recommended Posts

$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

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]);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.