Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Like php array_key_exists, this instead search if (one or more) keys exists in the array
- * @param array $needles - keys to look for in the array
- * @param array $haystack - the <b>Associative</b> array to search
- * @param bool $all - [Optional] if false then checks if some keys are found
- * @return bool true if the needles are found else false. <br>
- * Note: if hastack is multidimentional only the first layer is checked<br>,
- * the needles should <b>not be<b> an associative array else it returns false<br>
- * The array to search must be associative array too else false may be returned
- */
- public function array_keys_exists($needles, $haystack, $all = true)
- {
- $size = count($needles);
- if($all) return count(array_intersect($needles, array_keys($haystack))) === $size;
- return !empty(array_intersect($needles, array_keys($haystack)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement