Php judges that the array is empty two instances _ PHP Tutorial

Source: Internet
Author: User
Php judges that the array is empty for two instances. 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 the php code below the cou to provide two arrays to judge as null. because the array is a composite data type, we cannot process it like other types of data. 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:

$ 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:
/**
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 );
}
}

Bytes. Method 1. use cou...

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.