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



Custom Search