Some PHP syntax Problems

Source: Internet
Author: User
When I first came into contact with PHP, I wanted to use PHP to print the first line of the long-time multiplication table, as shown below: {code ...} the browser reports an error and prompts a syntax error. If I put 1 * $ I in a variable and splice it, there is no error. Why? {Code...} I want to use PHP to print the first line of the multiplication table for a long time, as shown below:

    $i = 9;    for($i = 1; $i <= 9; $i++) {        echo '1 * '.$i.' = '.1*$i;    }

The browser prompts a syntax error when an error is reported,
If I put 1 * $ I in a variable and splice it, there is no error. Why?

    $i = 9;    for($i = 1; $i <= 9; $i++) {        $n = 1*$i;        echo '1 * '.$i.' = '.$n;    }

Reply content:

When I first came into contact with PHP, I wanted to use PHP to print the first line of the long-time multiplication table, as shown below:

    $i = 9;    for($i = 1; $i <= 9; $i++) {        echo '1 * '.$i.' = '.1*$i;    }

The browser prompts a syntax error when an error is reported,
If I put 1 * $ I in a variable and splice it, there is no error. Why?

    $i = 9;    for($i = 1; $i <= 9; $i++) {        $n = 1*$i;        echo '1 * '.$i.' = '.$n;    }

$ I = 9; for ($ I = 1; $ I <= 9; $ I ++) {echo '1 *'. $ I. '= '. (1 * $ I);}. If you do not add parentheses, First connect the link symbol to number 1 and multiply it by $ I, and an error will be reported.

'.1*$iThis write method will report an error, PHP thinks.It should be followed by a string or variable instead of an integer.

echo '1 * '.$i.' = '.1*$i; The following error is reported:
Parse error: syntax error, unexpected '. 1' (T_DNUMBER), expecting', 'or'; 'in F: \ xampp \ htdocs \ test. php on line 7

If there is no space between the dot connector and number 1, the dot is not a connector at this time, and there is no space between the dot connector and number 1 to indicate 0.1, there is no connector at this time, so the syntax error is reported.

If you need to verify the above, you can add one before ". 1.
The statement becomesecho '1 * '.$i.' = '..1*$i;
The first vertex represents the connector, and the second vertex is a decimal abbreviation, 0.1.

Note that you can use a dot connector to connect numbers by adding spaces or parentheses.

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.