tags:

views:

34

answers:

3

I have an array of string i need to search an string inside the array using regex is it possible if so please explain..

+1  A: 

You can use a foreach loop to loop through all the elements and use a preg_match on each of them. If it matches, add it to an array of matches.

foreach($array as $check) {
    if (preg_match("/expression/", $check)) $matches[] = $check;
}

Very simple example.

animuson
A: 

You can iterate through the array using a foreach loop and search for the key in each element. An example:

<?php

$days = array('Sunday','Monday','Tuesday');
$key = "Sunday";

foreach($days as $day) {

    if(preg_match("/$key/",$day)) {
        echo "Key $key found !!";
    }
}
?>
codaddict
+4  A: 
$a = preg_grep("/search_word/",$array_of_strings);
print_r($a);
ghostdog74