Quantcast
Viewing all articles
Browse latest Browse all 22

Answer by Petr Cibulka for How to check if multiple array keys exists

It seems to me, that the easiest method by far would be this:

$required = array('a','b','c','d');$values = array('a' => '1','b' => '2');$missing = array_diff_key(array_flip($required), $values);

Prints:

Array(    [c] => 2    [d] => 3)

This also allows to check which keys are missing exactly. This might be useful for error handling.


Viewing all articles
Browse latest Browse all 22

Trending Articles