Is this unnecessary code?

Source: Internet
Author: User
Is this an array of redundant code: $ list
If ($ list & count ($ list)> 0 ){
Echo 'not blank ';
} Else {
Echo 'Empty ';
}
Code: count ($ list)> 0 is unnecessary?


Reply to discussion (solution)

If you select between $ list and count ($ list)> 0, it is unnecessary. the purpose of repeated judgment is to prevent multiple situations!

If you select between $ list and count ($ list)> 0, it is unnecessary. the purpose of repeated judgment is to prevent multiple situations!


Let me give an example of what happened.

In many cases, subsequent code or previous code needs to be combined with context.

This is basically redundant. If it is an array, $ list and count ($ list)> 0 are basically equivalent.

Note that:
Although the count function is designed to calculate the number of elements in an array, you can also pass a string as a parameter:
$ Str = ""; // empty string
Var_dump ($ str); // string (0 )""
Var_dump (count ($ str); // int (1)
Of course, this has nothing to do with this question... Can be ignored

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.