PHP: finds value in array and returns another value when found

advertisements

Totally a PHP noob here so sorry for the possibly basic question - here is what I'm trying achieve. I've got a dynamically generated array that looks something like:

$crumbs = 

(

[home] => Array (
[label] => Home
[title] => Go to Home Page
[first] => 1
[last] =>
[readonly] =>
) 

[something] => Array (
[label] => Shop
[title] =>
[first] =>
[last] => 1
[readonly] =>
) 

)

I'm trying to figure out how I can write something to go through and search (at any depth) to see which array has the key "last" set to a value of 1. When the array with the key is found, I need to then echo out the "label" key for the array which had last = 1. Every array will always have a label key and only one array will ever have the "last" key set to 1. Thanks as always for the help!


$iterator = new RecursiveArrayIterator($crumbs);

foreach($iterator as $arr) {
  if($arr['last'] == 1) {
    echo $arr['label'];
  }
}