Posted By

MonsterDev on 07/13/12


Tagged

search array


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tux-world


Recursive Array Key Search


 / Published in: PHP
 

Search recursively some value in array with the key name

  1. public static function recursive_array_key_search($needle, $key, $haystack)
  2. {
  3. $recursive_array_key_search = false;
  4.  
  5. if (in_array($needle, $haystack)) {
  6. $recursive_array_key_search = true;
  7. } else {
  8. foreach( $haystack as $key1 => $val ) {
  9. if(is_array($val)) {
  10. if(self::recursive_array_key_search($needle, $key, $val)) {
  11. $recursive_array_key_search = true;
  12. break;
  13. }
  14. }
  15. }
  16. }
  17. return $recursive_array_key_search;
  18. }

Report this snippet  

You need to login to post a comment.