Php judges the code of an empty array program

Source: Internet
Author: User

Empty function, which determines that the array value is null

The code is as follows: Copy code

$ Arr = array ("");
$ Result = empty ($ arr );
// $ Result = false
$ Arr = array ();
$ Result = empty ($ arr );
// $ 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 code is as follows: Copy code

$ Arr = array (), array (), array ());

$ Str = implode (',', $ arr );

If (empty ($ str) echo "null ";

Else echo "not empty ";


Array_filter function

The code is as follows: Copy code


<? Php
$ Str1_array = array ('yunqi Community Network ', '', 'http: // www.111cn.net','', '123 ','');
$ Str1_array = array_filter ($ str1_array );
Print_r ($ str1_array );
?>

Result

Array
(
[0] => Yunqi Community Network
Http://www.111cn.net
[4] = & gt; 1654
)

Count, size () function

These two functions are the method code used to judge an empty array.


$ Arr = array ("");
Echo count ($ arr );
Echo size ($ arr );
// 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.