Posted By

Japan on 03/25/11


Tagged

search array recursive key Value nested BY


Versions (?)

nested Array search by value or key


 / Published in: PHP
 

  1. <?php
  2.  
  3. //PHP 5.3
  4.  
  5. function searchNestedArray(array $array, $search, $mode = 'value') {
  6.  
  7. foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($array)) as $key => $value) {
  8. if ($search === ${${"mode"}})
  9. return true;
  10. }
  11. return false;
  12. }
  13.  
  14. $data = array(
  15. array('abc', 'ddd'),
  16. 'ccc',
  17. 'bbb',
  18. array('aaa', array('yyy', 'mp' => 555))
  19. );
  20.  
  21. var_dump(searchNestedArray($data, 555));

Report this snippet  

You need to login to post a comment.