docs:tips_n_tricks:php.html
This is an old revision of the document!
PHP
Meaning of isset() and empty()
~ $ php --version PHP 5.3.8 (cli) (built: Dec 5 2011 21:24:09) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
<? print "PHP Version is ".phpversion()."\n"; print '+---------------'; print '+-----------' ; print '+-----------' ; print "+\n"; print '| value '; print '| isset() ' ; print '| empty() ' ; print "|\n"; print '+---------------'; print '+-----------' ; print '+-----------' ; print "+\n"; print '| $foobar '; $foobar = NULL; if(isset($foobar)) print '| set ' ; else print '| not set ' ; if(empty($foobar)) print '| empty ' ; else print '| not empty ' ; print "|\n"; print '| $foobar = 0 '; $foobar = 0; if(isset($foobar)) print '| set ' ; else print '| not set ' ; if(empty($foobar)) print '| empty ' ; else print '| not empty ' ; print "|\n"; print '| $foobar = "" '; $foobar = ""; if(isset($foobar)) print '| set ' ; else print '| not set ' ; if(empty($foobar)) print '| empty ' ; else print '| not empty ' ; print "|\n"; print '| $foobar = 42 '; $foobar = 42; if(isset($foobar)) print '| set ' ; else print '| not set ' ; if(empty($foobar)) print '| empty ' ; else print '| not empty ' ; print "|\n"; print '| $foobar = "42"'; $foobar = "42"; if(isset($foobar)) print '| set ' ; else print '| not set ' ; if(empty($foobar)) print '| empty ' ; else print '| not empty ' ; print "|\n"; print '| $foobar = "x" '; $foobar = "x"; if(isset($foobar)) print '| set ' ; else print '| not set ' ; if(empty($foobar)) print '| empty ' ; else print '| not empty ' ; print "|\n"; print '| $foobar = NULL'; $foobar = NULL; if(isset($foobar)) print '| set ' ; else print '| not set ' ; if(empty($foobar)) print '| empty ' ; else print '| not empty ' ; print "|\n"; print '+---------------'; print '+-----------' ; print '+-----------' ; print "+\n";
gives
PHP Version is 5.3.8 +---------------+-----------+-----------+ | value | isset() | empty() | +---------------+-----------+-----------+ | $foobar | not set | empty | | $foobar = 0 | set | empty | | $foobar = "" | set | empty | | $foobar = 42 | set | not empty | | $foobar = "42"| set | not empty | | $foobar = "x" | set | not empty | | $foobar = NULL| not set | empty | +---------------+-----------+-----------+
docs/tips_n_tricks/php.html.1331197466.txt.gz · Last modified: 08.03.2012 10:04 CET by peter