Created
June 23, 2021 16:23
-
-
Save stefan2904/669dc8bb6395f34250ceab7cbc517731 to your computer and use it in GitHub Desktop.
PHP: Check if property exists in decoded JSON (using strict types)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; | |
$j = json_decode($json); | |
var_dump($j); | |
var_dump($j->a == NULL); | |
//var_dump($j->a === NULL); | |
var_dump(property_exists($j, 'a')); | |
var_dump(property_exists($j, 'aaaaaaa')); | |
//var_dump($j->aaaaa == NULL); | |
//var_dump($j->aaaaa === NULL); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment