How do you check if a variable is set or not in PHP?
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
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I escape a string with slashes?How do I remove trailing whitespace from a string?
How do I print text to the screen?
How do I reverse a string in PHP?
How do I find the length of a string in PHP?
