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 print text to the screen?How do I count the number of words in my text?
What is the difference between join and implode in PHP?
How do I join strings together?
How do I make the first letter of a string uppercase?
