PHP: Find element with certain property value in array

Posted by Svish on Stack Overflow See other posts from Stack Overflow or by Svish
Published on 2010-06-15T18:27:38Z Indexed on 2010/06/15 18:32 UTC
Read the original article Hit count: 212

Filed under:
|
|

I'm sure there is an easy way to do this, but I can't think of it right now. Is there an array function or something that lets me search through an array and find the item that has a certain property value? For example:

$people = array(
  array(
    'name' => 'Alice',
    'age' => 25,
  ),
  array(
    'name' => 'Waldo',
    'age' => 89,
  ),
  array(
    'name' => 'Bob',
    'age' => 27,
  ),
);

How can I find and get Waldo?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays