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

<?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 :)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.