FatMan
0
Q:

php check if variable exists

<?php

  $a = 0;
// True because $a is set
if (isset($a)) {
  echo 
  "Variable 'a' is set.<br>";
}

$b = null;
// False because $b is 
  NULL
if (isset($b)) {
  echo "Variable 'b' is set.";
}
?>
 
4
if (isset($var)) {
  // Code here
}
2

<?php

  $a = 0;
// True because $a is set
if (isset($a)) {
  echo 
  "Variable 'a' is set.<br>";
}

$b = null;
// False because $b is 
  NULL
if (isset($b)) {
  echo "Variable 'b' is set.";
}
?>
 
1
The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL.

This function returns true if the variable exists and is not NULL, otherwise it returns false.
1

New to Communities?

Join the community