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?
With the following snippet you have a general idea how to do it:
Then you can make the previous snippet as a general use function like:
And use it like this:
But watch out as the function can return 0 and false which both evaluates to false (use something like if ($foundIndex !== false) or if ($foundIndex === false)).