Null (PHP): verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(Nieuwe pagina aangemaakt met '== Set a variable to null == [https://stackoverflow.com/questions/1854288/how-to-reset-a-variable-to-null-in-php]: <pre> $x = null; </pre> == Bronnen == * https...') |
|||
Regel 5: | Regel 5: | ||
<pre> | <pre> | ||
$x = null; | $x = null; | ||
+ | </pre> | ||
+ | |||
+ | == Check for null == | ||
+ | |||
+ | Gewoon: <code>is_null()</code> [https://www.codepunker.com/blog/is-null-vs-empty-vs-isset-one-lesson-all-php-coders-should-learn]: | ||
+ | |||
+ | <pre> | ||
+ | $myvar = NULL; is_null($myvar); // This is TRUE | ||
+ | $myvar = 0; is_null($myvar); // This is FALSE | ||
+ | $myvar = FALSE; is_null($myvar); // This is FALSE | ||
+ | $myvar = ''; is_null($myvar); // This is FALSE | ||
+ | is_null($some_undefined_var); // This is also TRUE ... but the script throws a notice because $some_undefined_var doesn't exist | ||
</pre> | </pre> | ||
Regel 10: | Regel 22: | ||
* https://stackoverflow.com/questions/1854288/how-to-reset-a-variable-to-null-in-php | * https://stackoverflow.com/questions/1854288/how-to-reset-a-variable-to-null-in-php | ||
+ | * https://www.codepunker.com/blog/is-null-vs-empty-vs-isset-one-lesson-all-php-coders-should-learn |
Versie van 9 aug 2019 09:58
Set a variable to null
[1]:
$x = null;
Check for null
Gewoon: is_null()
[2]:
$myvar = NULL; is_null($myvar); // This is TRUE $myvar = 0; is_null($myvar); // This is FALSE $myvar = FALSE; is_null($myvar); // This is FALSE $myvar = ''; is_null($myvar); // This is FALSE is_null($some_undefined_var); // This is also TRUE ... but the script throws a notice because $some_undefined_var doesn't exist