Php checks whether 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

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 obtain null records. 0 is returned. 2. use the is_null function. the code is as follows:

  1. $ A = array ('1', '2', '3 ');
  2. Echo count ($ );
  3.  
  4. If (is_null ($ )){
  5. Echo '000 ';
  6. } Else {
  7. Echo & quot; 1111 & quot ";
  8. }
  9. ?>

The count method is feasible, but the is_null method is not.

Instance 2,Check whether an array is empty. the code is as follows:

  1. /**
  2. Array (
  3. ); Null
  4. Array (
  5. Array (
  6. ),
  7. Array (
  8. ),
  9. Array (
  10. )
  11. ); Null
  12. Array (
  13. Array (
  14. ),
  15. Array (
  16. Array (
  17. ),
  18. Array (
  19. 1 => 1
  20. )
  21. ),
  22. Array (
  23. )
  24. ); Not empty
  25. */
  26. Function is_array_null ($ value)
  27. {
  28. If (emptyempty ($ value ))
  29. {
  30. Return $ value;
  31. }
  32. Else
  33. {
  34. Return is_array ($ value )? Array_map ('Array _ Null', $ value): addslashes ($ value );
  35. }
  36. }

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.