Correct PHP code to check if a variable exists Correct PHP code to check if a variable exists json json

Correct PHP code to check if a variable exists


Use isset as a general purpose check (you could also use property_exists since you're dealing with an object):

if (isset($msgArray->sciID)) {    echo "Has sciID";}


In case isset() or property_exists() doesn't work, we can use array_key_exists()

if (array_key_exists("key", $array)) {    echo "Has key";}