How to check whether a variable is set or not using PHP ? Last Updated : 01 Jun, 2020 Comments Improve Suggest changes Like Article Like Report We have given a variable and the task is to check whether a variable var is set or not in PHP. In order to do this task, we have the following methods in PHP: Approach 1: Using isset() Method: The isset() method returns True if the variable is declared and its value is not equal to NULL. Syntax: bool isset( mixed $var [, mixed $... ] ) Example : PHP <?php // PHP program to check whether // a variable is set or not $str = "GeeksforGeeks"; // Check value of variable is set or not if(isset($str)) { echo "Value of variable is set"; } else { echo "Value of variable is not set"; } ?> OutputValue of variable is set Approach 2: Using !empty() Method: The empty() method returns True if the variable is declared and its value is equal to empty and not a set. Syntax: bool empty( $var ) Example : PHP <?php // PHP program to check whether // a variable is set or not $str = "GeeksforGeeks"; // Check value of variable is set or not if(!empty($str)) { echo "Value of variable is set"; } else { echo "Value of variable is not set"; } ?> OutputValue of variable is set Approach 3: Using !is_null() Method: The is_null() method returns True if the variable is declared and its value is equal to Null and not a set. Syntax: bool empty( $var ) Example : PHP <?php // PHP program to check whether // a variable is set or not $str = "GeeksforGeeks"; // Check value of variable is set or not if(!is_null($str)) { echo "Value of variable is set"; } else { echo "Value of variable is not set"; } ?> OutputValue of variable is set Comment More infoAdvertise with us Next Article How to check whether a variable is set or not using PHP ? S SHUBHAMSINGH10 Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-Misc Similar Reads How to check Whether a Variable is Null in PHP? We are given a variable and the task is to check whether the value of the given variable is null or not and returns a Boolean value using PHP. To check a variable is null or not, we use is_null() function. A variable is considered to be NULL if it does not store any value. It returns TRUE if the val 1 min read How to check whether an array is empty using PHP? Arrays are commonly used data structures that can hold multiple values. Sometimes it is necessary to check if an array is empty or not, and it is an important task to avoid errors when working with data. PHP offers several easy and effective ways to check if an array is empty. Below are the most com 3 min read PHP Program to Check if Two Strings are Same or Not Given two strings, the task is to check whether two strings are same or not in PHP. In this article, we will be looking at different approaches to check two strings are same or not. Examples: Input: str1 = "Geeks", str2 = "Geeks" Output: Both Strings are the same Input: str1 = "Hello", str2 = "Geeks 2 min read How to check the existence of URL in PHP? Existence of an URL can be checked by checking the status code in the response header. The status code 200 is Standard response for successful HTTP requests and status code 404 means URL doesn't exist. Used Functions: get_headers() Function: It fetches all the headers sent by the server in response 2 min read How to Check all values of an array are equal or not in PHP? Given an array with some elements, the task is to check whether all values of array elements are equal or not. Below are the approaches to check if all values of an array are equal or not in PHP: Table of Content Using array_unique() FunctionUsing array_reduce() FunctionUsing array_filter() Function 4 min read Like