PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

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


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
?>



More strings PHP Questions

How do I replace a word in a string in PHP?
How can I repeat a string variable several times?
How do I find the length of a string in PHP?
How do I check if a string contains HTML?
What is the difference between print and echo?