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 find the last occurrence of a character in a string?How do we count paragraphs or newlines?
How do I find the ASCII value of a string character?
how to compare strings in PHP?
How do I format the output of a string?
