Search DaTutorials:  
HOME
Php Tutorials
Articles
Basics
Date and Time
File Manipulations
Forms
Functions
General
Interactivity
MySql
Navigation
News,Shoutboxes and Blogs
Language Structure and Data Types
Searching
Security
String Manipulation
User Information and Stats
Search For a Tutorial
Php Reference

empty

(PHP 3, PHP 4, PHP 5 )

empty -- Determine whether a variable is empty

Description

bool empty ( mixed var)

empty() returns FALSE if var has a non-empty and non-zero value. In otherwords, "", 0, "0", NULL, FALSE, array(), var $var;, and objects with empty properties, are all considered empty. TRUE is returned if var is empty.

empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. See converting to boolean for more information.

Example 1. A simple empty() / isset() comparison.

<?php
$var
= 0;

// Evaluates to true because $var is empty
if (empty($var)) {
   echo
'$var is either 0, empty, or not set at all';
}

// Evaluates as true because $var is set
if (isset($var)) {
   echo
'$var is set even though it is empty';
}
?>

Note: Because this is a language construct and not a function, it cannot be called using variable functions

Note: empty() only checks variables as anything else will result in a parse error. In otherwords, the following will not work: empty(addslashes($name)).

See also isset(), unset(), array_key_exists(), count(), strlen(), and the type comparison tables.



Copyright © 2001-2004 The PHP Group
All rights reserved.

     TFT Monitor | Mortgages | Advertising | Mortgage Loans | Free Advertising
Home     Link To Us     Ad With Us     Contact Us     Tell A Friend     Affiliates     Blog     MsOfficeHelp