PHP isset() Function (original) (raw)
Last Updated : 24 Sep, 2024
The **isset() function in PHP checks whether a variable is declared and not NULL. It returns true if the variable exists and has a non-NULL value, and false otherwise, without modifying the variable.
**Syntax
bool isset( mixed var[,mixedvar [, mixed var[,mixed... ] )
**Parameters:
This function accept one or more parameter as mentioned above and described below:
- ****$var:** It contains the variable which need to check.
- ****$…:** It contains the list of other variables.
**Return Value: It returns TRUE if var exists and its value not equal to NULL and FALSE otherwise. Below examples illustrate the isset() function in PHP:
**Example 1: In this example we checks if the strvariableissetusingisset().Italsoverifiesifthefirstelementofanemptyarraystr variable is set using isset(). It also verifies if the first element of an empty array strvariableissetusingisset().Italsoverifiesifthefirstelementofanemptyarrayarr is set, printing appropriate messages for both checks.
php `
`
Output
Value of variable is set Array is Empty
**Example 2: In this example we use isset() to check if the variable numandspecificelementsinthenum and specific elements in the numandspecificelementsinthearr array are set. It outputs true for existing elements and false for non-existent ones.
php `
"Welcome", "b" => "to", "c" => "GeeksforGeeks" ); var_dump(isset($arr["a"])); var_dump(isset($arr["b"])); var_dump(isset($arr["c"])); var_dump(isset($arr["Geeks"])); ?>`
Output
bool(true) bool(true) bool(true) bool(true) bool(false)