Recursive Array Key Search


/ Published in: PHP
Save to your folder(s)

Search recursively some value in array with the key name


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.