isset()
18th January 2021
0 Comments
Programming Language
PHP [Versions: 4, 5, 7, 8]
Syntax
Typical Usage
Used to check if a PHP variable is declared and is something other than null. Most often used for GET and POST parameters.
Accepted Parameters
- variable (mixed) (Required): The variable you need to check for.
Return Value(s)
Returns true if the variable exists and has any value other than null and false if not.Notes
isset() only works with variables. Passing anything else will result in a parse error. If you need to check if a constant has been defined, use the defined() function.
Examples of isset()
Example 1
<?php
if (isset($_GET['name'])) {
echo $_GET['name'];
}
Example 2
<?php
if (isset($name)) {
echo 'Hello ' . $name;
}
else {
echo 'Hello User';
}
Used In Projects
Was This Helpful?
If this post has helped you, please let me know. Your feedback will be highly appreciated and will help me build better content.