User Tools

Site Tools


docs:tips_n_tricks:php.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
docs:tips_n_tricks:php.html [08.03.2012 09:51 CET] – created peterdocs:tips_n_tricks:php.html [08.03.2012 10:23 CET] (current) peter
Line 2: Line 2:
  
 ===== Meaning of isset() and empty()  ===== ===== 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       ';     print '| $foobar       ';
Line 28: Line 50:
     else               print '| not empty ' ;     else               print '| not empty ' ;
     print "|\n";     print "|\n";
 +  
     print '| $foobar = 42  ';     print '| $foobar = 42  ';
     $foobar = 42;     $foobar = 42;
Line 60: Line 82:
     else               print '| not empty ' ;     else               print '| not empty ' ;
     print "|\n";     print "|\n";
 +  
 +    print '+---------------';
 +    print '+-----------' ;
 +    print '+-----------' ;
 +    print "+\n";
 +
 +or
 +
 +  <?
 +    print "PHP Version is ".phpversion()."\n";
 +    
 +    print '+-------------------';
 +    print '+-----------' ;
 +    print '+-----------' ;
 +    print "+\n";
 +  
 +    print '| value             ';
 +    print '| isset()   ' ;
 +    print '| empty()   ' ;
 +    print "|\n";
 +  
 +    print '+-------------------';
 +    print '+-----------' ;
 +    print '+-----------' ;
 +    print "+\n";
 +  
 +    printf('| $foobar   %-7s | %-9s | %-9s |'."\n",''       ,(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +  
 +    $foobar = 0;
 +    printf('| $foobar = %-7s | %-9s | %-9s |'."\n",'0'      ,(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +  
 +    $foobar = "";
 +    printf('| $foobar = %-7s | %-9s | %-9s |'."\n",'""'     ,(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +  
 +    $foobar = 42;
 +    printf('| $foobar = %-7s | %-9s | %-9s |'."\n",'42'     ,(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +      $foobar = "42";
 +    printf('| $foobar = %-7s | %-9s | %-9s |'."\n",'"42"'   ,(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +  
 +    $foobar = "x";
 +    printf('| $foobar = %-7s | %-9s | %-9s |'."\n",'"x"'    ,(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +  
 +    $foobar = array();
 +    printf('| $foobar = %-7s | %-9s | %-9s |'."\n",'array()',(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +  
 +    $foobar = NULL;
 +    printf('| $foobar = %-7s | %-9s | %-9s |'."\n",'NULL'   ,(isset($foobar) ? '' : 'not ').'set',(empty($foobar) ? '' : 'not ').'empty' );
 +  
 +    print '+-------------------';
 +    print '+-----------' ;
 +    print '+-----------' ;
 +    print "+\n";
 +
 +
  
 gives  gives 
  
 +  PHP Version is 5.3.8
 +  +---------------+-----------+-----------+
 +  | value         | isset()   | empty()   |
 +  +---------------+-----------+-----------+
   | $foobar       | not set   | empty     |   | $foobar       | not set   | empty     |
   | $foobar = 0   | set       | empty     |   | $foobar = 0   | set       | empty     |
Line 70: Line 150:
   | $foobar = "x" | set       | not empty |   | $foobar = "x" | set       | not empty |
   | $foobar = NULL| not set   | empty     |   | $foobar = NULL| not set   | empty     |
 +  +---------------+-----------+-----------+
 +
  
docs/tips_n_tricks/php.html.1331196686.txt.gz · Last modified: 08.03.2012 09:51 CET by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki