Created
December 23, 2018 17:57
-
-
Save johnabela/e50390380ceebc1dfd76e50f9c26d88a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check to see if an array is suppose to have specific keys. | |
* This does not check to see if the keys have any values, it | |
* only checks to see if the keys exists. | |
* | |
* @usage | |
* $array = ['key' => 'meh', 'secret' => 'why']; | |
* $requiredKeys = ['key', 'secret']; | |
* array_RequiredKeys($requiredKeys, $array); | |
* | |
* @author John B. Abela <github:johnabela> | |
* @created December 23, 2018 08:25 AM | |
* @version 1.0.0 | |
* @return null | |
*/ | |
function array_RequiredKeys($requiredKeys, $array) { | |
// | |
if (!is_array($array)) { | |
die("The array we are suppose to check is not an array."); | |
} | |
// | |
if (!is_array($requiredKeys)) { | |
die("The requiredKeys array is not an array."); | |
} | |
// | |
foreach ($requiredKeys as $key) { | |
// | |
if (!array_key_exists($key, $array)) { | |
die("Missing a required array key: " . $key); | |
} | |
// | |
if (!is_string($array[$key])) { | |
die("The array key '" . $key . "' must be a string."); | |
} | |
// | |
} | |
// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment