MySQL SELECT WHERE php数组等价[关闭]

I am wanting to know if there is such a thing like the MySQL SELECT WHERE but in arrays.

I have this array:

$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?

You're looking for array_filter:

array_filter($array, function ($v) { return $v["test2"] === "2"; });

There is an sql4array class that allows you to use SQL to retrieve data from a PHP array, although I've never used it and can't comment on how good it is. The developers do acknowledge that it is slow though, and doesn't support the entirety of SQL syntax.

There is also PHPLinq or alternatives that use Language Integrated Query such as plinq and linqforphp.

Personally, I'd be inclined to use array_filter()