The empty() function is an inbuilt function in PHP which is used to check whether a variable is empty or not.
bool empty ( $var )
Parameter: This function accepts a single parameter as shown in above syntax and described below.
- $var: Variable to check whether it is empty or not.
Note: Below version of PHP 5.5, empty() only supports variables, anything other will result in a parse error. The following statement will not work empty(trim($var)). Instead, use trim($name) == false.
Return Value: It returns FALSE when $var exists and has a non-empty, non-zero value. Otherwise it returns TRUE.
These values are considered to be as an empty value:
- “” (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float)
- “0” (0 as a string)
- array() (an empty array)
Below program illustrate the empty() function in PHP:
True True True True True True True True
Reference : http://php.net/manual/en/function.empty.php
- D3.js | d3.set.empty() Function
- D3.js | d3.map.empty() Function
- Why to check both isset() and !empty() function in PHP ?
- CSS | :empty Selector
- CSS | empty-cells Property
- Best way to initialize empty array in PHP
- jQuery | :empty Selector
- How to check whether an array is empty using PHP?
- How to check an HTML element is empty using jQuery ?
- Program to remove empty array elements in PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.