Php judges the code of an empty array program

Source: Internet
Author: User
Many of my friends asked me how to judge the php empty array. next I will summarize some common code used to judge the empty array program. if you need to know about it, please refer to the empty function. this is to judge the array value.

Many of my friends asked me how to judge the php empty array. I will summarize some common code used to judge the empty array program. if you need to know it, please refer to it.

Empty function, which determines that the array value is null

The instance code is as follows:

  1. $ Arr = array ("");
  2. $ Result = emptyempty ($ arr );
  3. // $ Result = false
  4. $ Arr = array ();
  5. $ Result = emptyempty ($ arr );
  6. // $ Result = true

Implode ();

Use implode () to output the array as a string and determine whether the output string is null. it seems to be a good method at the beginning, but unfortunately it keeps up with 1.1. it won't work for arrays above two dimensions. for example:

The instance code is as follows:

  1. $ Arr = array (), array (), array ());
  2. $ Str = implode (',', $ arr );
  3. If (emptyempty ($ str) echo "null ";
  4. Else echo "not empty ";

Array_filter function

The instance code is as follows:

  1. $ Str1_array = array ('one-click tutorial net', '', 'http: // www.111cn.net ','', '123 ','');
  2. $ Str1_array = array_filter ($ str1_array );
  3. Print_r ($ str1_array );
  4. ?>

Result

Array ([0] => a Poly tutorial network [2] => http://www.111cn.net [4] => 1654)

Count, size () function

The two functions are the method code for determining the null array:

  1. $ Arr = array ("");
  2. Echo count ($ arr );
  3. Echo size ($ arr );
  4. // Output 1

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.