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.