Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[php5.6] array_keys_exist
<?php
if (!function_exists('array_keys_exist')) {
/**
* Checks if given keys or indexes exist in the array.
*
* @author Ozgur Giritli <ozgur@zeronights.com>
*
* @param array $array Array to check keys against.
* @param mixed $keys Key to check existance of.
* @param mixed $keys,... Additional keys to check existance of.
* @return boolean
*/
function array_keys_exist($array, ...$keys) {
return count(array_intersect_key(array_flip($keys), $array)) === count($keys);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment