PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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



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?



Custom Search