Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. /**
  2. * Like php array_key_exists, this instead search if (one or more) keys exists in the array
  3. * @param array $needles - keys to look for in the array
  4. * @param array $haystack - the <b>Associative</b> array to search
  5. * @param bool $all - [Optional] if false then checks if some keys are found
  6. * @return bool true if the needles are found else false. <br>
  7. * Note: if hastack is multidimentional only the first layer is checked<br>,
  8. * the needles should <b>not be<b> an associative array else it returns false<br>
  9. * The array to search must be associative array too else false may be returned
  10. */
  11. public function array_keys_exists($needles, $haystack, $all = true)
  12. {
  13. $size = count($needles);
  14. if($all) return count(array_intersect($needles, array_keys($haystack))) === $size;
  15. return !empty(array_intersect($needles, array_keys($haystack)));
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement