Phpempty () 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.

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.

  1. $ Array1 = array ();
  2. Print_r ($ array1 );
  3. If (emptyempty ($ array1 )){
  4. Echo 'for empty () is an empty array (an empty array )';
  5. }
  6. Else {
  7. Echo 'non-empty array (an noempty array) 'for empty )';
  8. }
  9. ?>

Display result: Array (), which is an empty array for empty ()

  1. $ Array1 = array ();
  2. $ Array1 [] = '';
  3. Print_r ($ array1 );
  4. If (emptyempty ($ array1 )){
  5. Echo 'for empty () is an empty array (an empty array )';
  6. }
  7. Else {
  8. Echo 'non-empty array (an noempty array) 'for empty )';
  9. }
  10. ?>

Display result: Array ([0] =>), which is a non-empty array (an noempty Array) for empty (). This is not an empty array, because it has an element that is null (""), it must be noted that it is different from the null character ("" (an empty string;

Actually:

Empty ($ x) equals! Isset ($ x) |! $ X

! Empty ($ x) equals isset ($ x) & $ x

Empty function syntax:Bool empty (mixed var)

Empty -- check whether a variable is empty.

Description: 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.