What is the use of isset() in PHP?
isset() checks whether a variable is set and is not NULL. It returns true if the variable exists and has a value, otherwise false.
<?php
$name = "Robin";
var_dump(isset($name));
var_dump(isset($age));
?>
Output:
Tutorials Class - Output Window
bool(true)
bool(false)
It is mostly used with forms, for example isset($_POST["email"]), to avoid “undefined index” warnings. Read the full chapter PHP isset() function, and learn the difference with empty().
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Variables |
| PHP Data Types |
| PHP Constants |
| PHP isset() Function |
| PHP empty() Function |
| PHP is_null() Function |
| Exercises & Assignments |
|---|
| Write a program to print “Hello PHP” using variable |
| Write a program to print a string using echo+variable. |
| Write a program to print two variables in single echo |