Determine whether a variable is considered to be empty.
But in my memory, for a long time I thought that empty should be able to judge whether something is empty until one day I am like this "EMPTY (TRIM ($ )) "an error occurs during use, and then
First, both of these functions are used to test the state of a variable:
The Isset () function determines if a variable returns true if it is present, otherwise it returns false.
The empty () function determines whether a variable is null
$a = 0; ==> compliant with Empty,empty ($a) is true$a = ' 0 '; ==> compliant with Empty,empty ($a) is true$a = "; ==> compliant with Empty,empty ($a) is true$a = "; ==> does not meet empty,empty ($a) for flase$a = null; ==> compliant with
When PHP is developed, when you use empty to check the results returned by a function, you will get an error: Fatal error:can ' t usage function return value in write context
For example, the following code:
Copy Code code as follows:
echo
Determine whether a variable is considered to be empty.
But for a long time in my memory, I thought empty should be able to judge whether a thing was empty until one day I was like this "empty (trim ($a))" When the use of the error occurred, And
Value.
For example.
Method 1:
CopyCodeThe Code is as follows: $ SQL = "select * Form ABC"
$ Result = mysql_query ($ SQL );
$ ROW = mysql_fetch_array ($ result );
If (empty ($ row) // start to judge whether it is null
{
Echo "null ";
}
During PHP development, when you use empty to check the results returned by a function, the following error occurs: Fatal error: Can't use function return value in write context.
For example, the following code:Copy codeThe Code is as follows:Echo
In the development process, often encountered in the judgment of the existence of variables and whether it is empty, especially the array, if the access to a non-existent element of the array, there will be a notice level of error burst, but also a
value to be judged.
Very simply, give an example.
Method One:
Copy Code code as follows:
$sql = "SELECT * Form ABC"
$result = mysql_query ($sql);
$row = Mysql_fetch_array ($result);
if (empty ($row))//start to judge is enough empty
{
JS Check is a numeric function and a non-empty functionCheck to see if it is not emptyfunction Notempty (obj, msg){str = Obj.value;STR1 = "";for (i = 0; i {if (Str.charat (i)!= ""){STR1 = Str.substr (i, str.length);Break}}if (str1 = ""){Alert
Values to be judged.
Very simple, give an example.
method One:
Copy CodeThe code is as follows:
$sql = "SELECT * Form ABC"
$result = mysql_query ($sql);
$row = Mysql_fetch_array ($result);
if (empty ($row))//Start judging is enough empty
{
echo
Empty to determine whether a variable is "empty", isset to determine whether a variable has been set. It is this so-called "as the name implies", so I began to take some detours: when a variable value equals 0 o'clock, empty () will also be set
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.