Php judges that the array is empty for two instances

Source: Internet
Author: User

The following provides the php code for determining whether the array is null. Because the array is a composite data type, we cannot process it like other complex data types. Let's look at the example below.

Method
1. Use count (array) to retrieve null records. 0 is returned.
2. Use the is_null Function

The Code is as follows: Copy code

<? Php
$ A = array ('1', '2', '3 ');
Echo count ($ );


If (is_null ($ )){
Echo '000 ';
} Else {
Echo & quot; 1111 & quot ";
}
?>

The count method is feasible.
The is_null method does not work.

Instance 2


// Determine whether an array is empty

The Code is as follows: Copy code
/**
Array (
); Null
Array (
Array (
),
Array (
),
Array (
)
); Null
Array (
Array (
),
Array (
Array (
),
Array (
1 => 1
)
),
Array (
)
); Not empty
*/
Function is_array_null ($ value)
{
If (empty ($ value ))
{
Return $ value;
}
Else
{
Return is_array ($ value )? Array_map ('array _ null', $ value): addslashes ($ value );
}
}

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.