I have two arrays: $values
and $availableKeys
. I want to throw an exception if $values
contains not allowed keys. At the moment I am running this code.
foreach ($values as $key => $value) {
if (!in_array($key, $availableKeys)) {
throw new RuntimeException(
'Not allowed key'
);
}
}
Exists a better way to validate an array? The question Validate PHP Array Key>Value is not responding to my question.