Search the blog

I was recently checking the integrity of some JSON that came from user input. This function is useful for checking you have a specific list of keys in an associative array.

					
function multipleArrayKeysExists($array, $keys) {

    $requiredKeys = $keys;
    $actualKeys   = array_keys($array);

    sort($requiredKeys);
    sort($actualKeys);

    if ($requiredKeys !== $actualKeys) {

        return false;

    }

    return true;

}					
				
Tim Bennett is a Leeds-based web designer from Yorkshire. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.