php - Access Multidimensional Array element with out knowing parent elements -


i have function returns following multidimensional array. don't have control of how array formed. im trying access 'result' elements. issue is, name of parent elements changing. location of 'result' element same (as name "result"). possible access element without know name of parent elements?

    array (     [sheader] => array         (             [aaction] => actionhere         )  [sbody] => array     (         [createpropertyresponse] => array             (                 [createpropertyresult] => array                     (                         [message] => completed operation                         [result] => 0                         [transactiondate] => 2013-05-19t21:54:35.765625z                         [bpropertyid] => 103                     )              )      ) 

)

an easy option search array keys/values recursively use recursive iterator; these built-in classes, part of standard php library.

$result   = false; $iterator = new recursiveiteratoriterator(new recursivearrayiterator($array)); foreach ($iterator $key => $value) {     if ($key === 'result') {         $result = $value;         break;     } }  var_dump($result); 

the bonus here could, if wanted to, check depth of result item ($iterator->getdepth()) in array structure and/or check 1 or more ancestor keys ($iterator->getsubiterator(…)->key()).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -