isset php: PHP isset() function | Exam-Lib
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
Welcome to our Education website, plz like our page facebook to support us. Thank You and wish you good navigation

isset php: PHP isset() function

abdelouafiApr 14, 2018

    1. abdelouafi

      abdelouafi Administrator Staff Member

      Messages:
      617
      Likes Received:
      12
      Trophy Points:
      18
      Joined
      Sep 13, 2016

      isset

      (PHP 4, PHP 5, PHP 7)

      isset — Determine si la variable contient une valeur (not NULL) ou non.
      Description
      Code:
      bool isset ( mixed $var [, mixed $... ] )
      Syntaxe:

      isset(variable1, variable2......)

      Valeur de retour:
      True si variable (variable1,variable2..) existent et possèdent des valeurs non null, FALSE dans le cas contraire.
      upload_2018-4-14_13-42-20.png

      Exemple:
      Code:
      <?php
      
      $var1 = 'test';
      var_dump(isset($var1));
      ?>
      Résultat d'exécution:
      bool(true)


      Exemple 2:
      Code:
      <?php
      
      
      $var = '';
      
      // This will evaluate to TRUE so the text will be printed.
      if (isset($var)) {
          echo "This var is set so I will print.";
      }
      
      // In the next examples we'll use var_dump to output
      // the return value of isset().
      
      $a = "test";
      $b = "anothertest";
      
      var_dump(isset($a));      // TRUE
      var_dump(isset($a, $b)); // TRUE
      
      unset ($a);
      
      var_dump(isset($a));     // FALSE
      var_dump(isset($a, $b)); // FALSE
      
      $foo = NULL;
      var_dump(isset($foo));   // FALSE
      
      ?>

      Exemple avec un tableau en PHP:
      Code:
      <?php
      
      
      $a = array ('test' => 1, 'hello' => NULL, 'pie' => array('a' => 'apple'));
      
      var_dump(isset($a['test']));            // TRUE
      var_dump(isset($a['foo']));             // FALSE
      var_dump(isset($a['hello']));           // FALSE
      
      // The key 'hello' equals NULL so is considered unset
      // If you want to check for NULL key values then try:
      var_dump(array_key_exists('hello', $a)); // TRUE
      
      // Checking deeper array values
      var_dump(isset($a['pie']['a']));        // TRUE
      var_dump(isset($a['pie']['b']));        // FALSE
      var_dump(isset($a['cake']['a']['b']));  // FALSE
      
      ?>

      Exemple avec PHP5 lorsqu'on on fait passer du chaine de caractère:

      Code:
      <?php
      $expected_array_got_string = 'somestring';
      var_dump(isset($expected_array_got_string['some_key']));
      var_dump(isset($expected_array_got_string[0]));
      var_dump(isset($expected_array_got_string['0']));
      var_dump(isset($expected_array_got_string[0.5]));
      var_dump(isset($expected_array_got_string['0.5']));
      var_dump(isset($expected_array_got_string['0 Mostel']));
      ?>
      L'exécution de ce code sous PHP 5.3 est:
      bool(true)
      bool(true)
      bool(true)
      bool(true)
      bool(true)
      bool(true)

       
      Loading...

Share This Page

Share