0

Hi everyone,

I am wanting to know if there is such a thing like the mySQL SELECT WHERE but in array's.

I have this array:

<?php
$array = array(
[1] = array(
['test'] = '1',
['test2'] = '2'
);
[2] = array(
['test'] = '4',
['test2'] = '2'
);
);
?>

I am basically wanting all the records where 'test2' = '2'. So my result should be the id's 1,2.

Can this be done if you get my drift. Its really hard to explain what im after.

Thanks,
Marais

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by scarcella
1
<?php

$array = array( 1 => array('test' => '1',	'test2' => '2'	),
                 2 => array('test' => '4','test2' => '2'
               )

);

foreach ($array as $masterkey => $aa) {
    foreach($aa as $key => $a) {
        if ($key == 'test2' && $a == '2') {
            echo $masterkey ;
        }
    }
}

?>

Assuming I understand your question , this should work :)

Edited by kutchbhi: n/a

0

Thank you kutchbhi, i have considered doing it that way, but don't you think that is a slow method? Is there maybe another way that is a bit faster. My array is about 40 records. So this is a bit slow...

By the way, how was my terminology? How should i have asked my question?

Thanks,
Marais

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.