Jump to content

[SOLVED] preg_match on a field within an array and output that complete array


gladideg

Recommended Posts

 

 

I have an array with 4 arrays inside, which again has 10 tab-seperated fields... I'm trying to match a value inside one of the 4 arrays, and if there was a match, I want to output or save that complete array as an new array I can reuse... I tried using preg_match, but I'm lost.

 

$theinstance = "i-dbc1b3";
$output = thearray....
echo "<pre>";
foreach($output as $row) {
echo "<pre>";
preg_match("(^$theinstance^)", $row, $instance);
print_r($instance);
echo "</pre>";
}
echo "</pre>";

Sorry for being unclear, my question was also wrong.

 

It's actually one array, with 4 key's with 14 fields, tab-separated.

 

I need to search this array for a match on "banana"

 

Then I need that complete row as an $array, where all fields can be extracted like : echo $array[5] .

 

Array
(
    [0] => 0	1	2	3	4	orange	6	7	8	9	10	11	12	13
    [1] => 0	1	2	3	4	apple         6	7	8	9	10	11	12	13
    [2] => 0	1	2	3	4	banana	6	7	8	9	10	11	12	13
    [3] => 0	1	2	3	4	foobar	6	7	8	9	10	11	12	13
)

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.