PHP empty() Function Last Updated : 24 Sep, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The empty() function in PHP checks whether a variable is empty. It returns true if the variable has a value considered "empty," such as 0, null, false, an empty string, or an unset variable, and false otherwise. Syntaxbool 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)NULLFALSEarray() (an empty array)Example: In this example we demonstrates the empty() function, which returns true for variables that are empty, such as 0, "0", NULL, false, empty arrays, empty strings, and undefined variables. php <?php // PHP code to demonstrate working of empty() function $var1 = 0; $var2 = 0.0; $var3 = "0"; $var4 = NULL; $var5 = false; $var6 = array(); $var7 = ""; // for value 0 as integer empty($var1) ? print_r("True\n") : print_r("False\n"); // for value 0.0 as float empty($var2) ? print_r("True\n") : print_r("False\n"); // for value 0 as string empty($var3) ? print_r("True\n") : print_r("False\n"); // for value Null empty($var4) ? print_r("True\n") : print_r("False\n"); // for value false empty($var5) ? print_r("True\n") : print_r("False\n"); // for array empty($var6) ? print_r("True\n") : print_r("False\n"); // for empty string empty($var7) ? print_r("True\n") : print_r("False\n"); // for not declare $var8 empty($var8) ? print_r("True\n") : print_r("False\n"); ?> OutputTrue True True True True True True True Comment More infoAdvertise with us Next Article PHP | exit( ) Function M Mithun Kumar Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP | exit( ) Function The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The message 2 min read PHP compact() Function The compact() function is an inbuilt function in PHP and it is used to create an array using variables. This function is the opposite of the extract() function. It creates an associative array whose keys are variable names and their corresponding values are array values. Syntax: array compact("varia 2 min read PHP end() Function The end() function is an inbuilt function in PHP and is used to find the last element of the given array. The end() function changes the internal pointer of an array to point to the last element and returns the value of the last element.Syntax:end($array)Parameters:This function accepts a single par 2 min read PHP decoct( ) Function In the earlier days of computing, octal numbers and the octal numbering system was very popular for counting inputs and outputs because as it works in counts of eight, inputs and outputs were in counts of eight, a byte at a time. Due to a wide usage of octal number system many times it happens that 2 min read PHP eval() Function PHP eval() function in PHP is an inbuilt function that evaluates a string as PHP code. Syntax: eval( $string ) Parameters: This function accepts a single parameter as shown in the above syntax and described below. $string: It must consist of a valid PHP code to be evaluated but should not contain op 2 min read PHP each() Function The each() function is an inbuilt function in PHP and is used to get the current element key-value pair of the given array to which the internal pointer is currently pointing. After returning the key and value of the current element the internal pointer is incremented by one in the array. Note: You 2 min read Like