Discussion board
How do you check if a variable is set or not in PHP?
By prabeen patra
How do you check if a variable is set or not in PHP????
Reply
Post   Reset
Teacher SiliconIndia replied to prabeen patra Wednesday, March 17, 2010
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
?>