Spelling mistakes that beginners might make to a PHP if-judgment statement

Source: Internet
Author: User

The main reason to write this is the last week after a typo error, but this is the correct standard grammar, will not produce syntax error, so bad Chase, and then make a record, then you can first grep to see if this typo error caused. Xd

Possible spelling mistakes in PHP if judgment

If the judgement type, there is a very common, but that is not typo error, but also very often such a written, is "=", "= =", "= =".
Example
View Raw Code?

<?php
if ($a = ' a ')
Echo ' This line is printed because $a = "a", and a is not 0/false, so it is true;
if ($a = = ' B ')
Echo ' This line will not be printed, because $a is equal to "a", not equal to "B";
if ($a = = true)
Echo ' This line will not be printed because the $a form is not true. (Of course the main value is wrong, but not discussed here) ';
?>

When in the program, accidentally delete the equal sign, it will cause great tragedy. (syntax is not checked out, is the correct wording)

The above is common, also difficult to chase, but the following is written for the first time met ~ (the "!=" into "=!", this should be 90% 9 is typo error.)
View Raw Code?

<?php
$a = ' B ';
if ($a!= ' a ')
echo $a; This line printed out ' B ', this is the thing to do.
When the!= hit =! , it will cause tragedy.
if ($a =! ' A ')
Echo ' This line will not be printed ';
Var_dump ($a); Print out false
?>

Problem Tracking Disassembly

Step by step decomposition $a =! A
$a =! ' Boolean of a '//' A ' is true,!true = False.
$a = False
So if ($a = false), will never fall into this row, syntax is also legal.

After Debug in addition to "=", "= =", "= = =" Outside, to pay more attention to see "!=" and "=!" of the wording.

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.