A little syntax problem with PHP

Source: Internet
Author: User
For the first time I contacted PHP, I wanted to use PHP to print out the first line of a long multiplication table, as follows:

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

Find the browser error, prompt syntax error,
And if I put 1* $i into a variable, and then do the stitching, then there is no error, excuse me, why is this?

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

Reply content:

For the first time I contacted PHP, I wanted to use PHP to print out the first line of a long multiplication table, as follows:

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

Find the browser error, prompt syntax error,
And if I put 1* $i into a variable, and then do the stitching, then there is no error, excuse me, why is this?

    $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);}这样做,因为你不加括号的话,首先链接符号连接数字1再乘以$i,就会报错了

'.1*$iThis is an error, and PHP thinks it should be a . string or a variable instead of an integral type.

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

If there is no space between the point connector and the number 1, the point is not a connector, there is no space between the point and the number 1 represents 0.1, there is no connector, so the syntax error.

If you need to verify the above, you can add one in front of ". 1".
At this point, the statement becomesecho '1 * '.$i.' = '..1*$i;
The first point represents the connector, the second point is the shorthand for the decimal, 0.1.

Connecting numbers with point connectors It is important to note that you can avoid such cases 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.