Ask in the IF statement! And empty is not the same;

Source: Internet
Author: User
$a =array (); $a = "; $a = "0"; $a =null; ...
if (empty ($a)) = = = if (! $a);

Recently see thinkphp Framework code, in the judgment statement, used a lot of empty () without!;

Ask: The framework writer is based on what purpose with empty () instead of!

Is it the empty ratio! Save server resources? Very confusing; I believe there must be a reason for asking why;







Reply to discussion (solution)

I think you made a mistake! The meaning of right and wrong.

if (empty ($a)) determines whether a $ A is empty, returns true for NULL, otherwise returns false
if (! $a) $a if there is a return of false, no returns True

! The logical operator is the inverse meaning.
Empty is the method.

The difference is that if $ A is not defined. Empty does not go wrong. and! $a will go wrong.

Var_dump (Empty ($a)); Var_dump (! $a);  Will prompt notice:undefined variable:a
  • 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.