Forum : How do you check if a variable is set or not in PHP?
Brief description  about Online courses   join in Online courses
View prabeen  patra 's Profile

How do you check if a variable is set or not in PHP?

How do you check if a variable is set or not in PHP????
Asked by prabeen patra | Mar 17, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Prabeen,
This is done using the isset keyword, which returns 1 if it is set or 0 if it is not.
It is important to note that if the variable is defined but set to 0 then it will still return 1.
<?php
function checksetting($var) {
if(isset($var)) { echo "Set"; } else { echo "Not set"; }
}
$a = 5; $b = 0;
checksetting($a); //set
checksetting($b); //set
?>
Mar 17, 2010