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.