Php null array code _ PHP Tutorial

Source: Internet
Author: User
Php judges the code of an empty array program. 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, this is to judge many friends asked how to judge the php empty array, next I will give you a summary of some common null array judgment program code, a friend who needs to know can go to the reference.

Empty function, which determines that the array value is null

The code is as follows:

$ 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:

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

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

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

Else echo "not empty ";


Array_filter function

The code is as follows:


$ Str1_array = array ('one-click tutorial net', '', 'http: // www. bKjia. c0m','', '123 ','');
$ Str1_array = array_filter ($ str1_array );
Print_r ($ str1_array );
?>

Result

Array
(
[0] => yijucheng
Http://www.bKjia. c0m
[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

Bytes. Empty function. this is judgment...

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.