Php empty () function details

Source: Internet
Author: User

Today I want to talk about the usage of the empty function, what is the difference between empty and other functions, and whether the normal value is returned when you use it to operate the array. If you need it, please refer to it.

 

The Code is as follows: Copy code
<? Php
$ Array1 = array ();
Print_r ($ array1 );
If (empty ($ array1 )){
Echo 'for empty () is an empty array (an empty array )';
}
Else {
Echo 'non-empty array (an noempty array) 'For empty )';
}
?>
Display result :######################
Array
(
)
For empty (), it is an empty array

###############################

 

The Code is as follows: Copy code
<? Php
$ Array1 = array ();
$ Array1 [] = '';
Print_r ($ array1 );
If (empty ($ array1 )){
Echo 'for empty () is an empty array (an empty array )';
}
Else {
Echo 'non-empty array (an noempty array) 'For empty )';
}
?>
Display result :######################
Array
(
[0] =>
)
Non-empty array (an noempty array) for empty)
###############################

 

This is not an empty array because it has an element that is a null character (""). Be sure to distinguish it from a null character ("" (an empty string;

Actually
Empty ($ x) equals! Isset ($ x) |! $ X
! Empty ($ x) equals isset ($ x) & $ x

Empty function syntax

Empty -- check whether a variable is empty
Description
Bool empty (mixed var)


If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.