Created
February 12, 2018 15:10
-
-
Save TakesTheBiscuit/f58034781e004b24d144ecaa41b4af69 to your computer and use it in GitHub Desktop.
PHP property exists check
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 | |
$str = json_encode(['test'=>true]); | |
$obj = json_decode($str); | |
var_dump($obj); | |
echo PHP_EOL.'<br>'; | |
$keys = [ | |
'tests', | |
'testies', | |
'test' | |
]; | |
foreach ($keys as $key) { | |
if (property_exists($obj, $key)) { | |
echo 'got '.$key; | |
} else { | |
echo $key. ' was not found'; | |
} | |
echo PHP_EOL.'<br>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And showing the values of an object through dynamic variable selection: