phparraysnullindexingisset

PHP - Checking if array index exist or is null


Is there a way to check if an array index exists or is null? isset() doesn't tell you whether the index doesn't exist or exists but is null. If I do : isset($array[$index]) || is_null($array[$index]) it won't work because if the index doesn't exist is_null will crash.

How can I check this please? Also is there a way to check only if something exist, no matter if it is set to null or not?


Solution

  • The function array_key_exists() can do that, and property_exists() for objects, plus what Vineet1982 said. Thanks for your help.