Home > Article > Backend Development > PHP basic operators, detailed examples of the difference between single quotes and double quotes
one. StringInsert
The difference between double quotes and single quotes:
1. The use of double quotes:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <?php //双引号可以解析变量和转义字符 $username = "jack"; echo "his name is $username!"; echo "<br/>"; $username = "小东"; //如果是英文的感叹号会正常解析变量 echo "他的名字是$username!";//他的名字是小东! echo "<br/>"; //如果是中文的感叹号则会解析不出来 echo "他的名字是$username!";//他的名字是 echo "<br/>"; //转义字符在这里虽然被解析出来了,但是\n是在源代码里换行 //浏览器显示只是一个字符的位置 echo "他的名字是$username,\n他今年20岁了";//他的名字是小东, 他今年20岁了 echo "<br/>"; //为了避免出现错误,推荐使用 字符串连接 的方式 echo "他的名字是".$username.",他今年20岁了";//他的名字是小东,他今年20岁了 ?>
2. The use of single quotes:
<?php //单引号只是输出字符串字面值, //不会解析变量和转义字符。 //也不会进行语法加亮提示 $username = 'anllin'; echo 'his name is $username,\n his age is 20.'; //output //his name is $username,\n his age is 20. ?>
Some commonly used escape characters
Escape sequence |
Description |
##\n |
Line break |
##\r
|
Enter
|
Backslash |
|
Dollar sign |
##\” |
Double quotes |
2. | Operator
##Instance one, <?php
//算术操作符
$a = 5;
$b = 3;
echo $a + $b;
echo '<br/>';
echo $a - $b;
echo '<br/>';
echo $a * $b;
echo '<br/>';
echo $a / $b;
echo '<br/>';
echo $a % $b;
?>
The results are as follows: 8
2
15
1.66666666667
2
Instance two,
<?php //复合赋值操作符 $a = 5; $b = 3; echo $a += $b; echo '<br/>'; echo $a -= $b; echo '<br/>'; echo $a *= $b; echo '<br/>'; echo $a /= $b; echo '<br/>'; echo $a %= $b; echo '<br/>'; echo $a .= $b; ?>The results are as follows:
8 5 15 5 2 23Instance three ,
<?php // 递增递减运算符 $a = 5; echo ++$a; echo '<br/>'; echo $a++; echo '<br/>'; echo --$a; echo '<br/>'; echo $a--; ?>
The results are as follows:
6 6 6 6
<?php $a = 5; $b = 3; $c = 5; $d = '5'; echo $a == $c; echo '<br/>'; echo $a === $c; echo '<br/>'; echo $a == $d; echo '<br/>'; echo $a != $b; echo '<br/>'; echo $a !== $d; echo '<br/>'; echo $a != $b; echo '<br/>'; echo $a > $b; echo '<br/>'; echo $b < $c; echo '<br/>'; echo $a >= $c; echo '<br/>'; echo $a <= $c; ?>
1 1 1 1 1 1 1 1 1 1
<?php $a = false; echo ! $a; echo '<br/>'; $b = 5; $c = 3; echo $b > 0 && $c > 0; echo '<br/>'; echo $b > 0 and $c > 0; echo '<br/>'; echo $b != 0 || $c != 0; echo '<br/>'; echo $b != 0 or $c != 0; echo '<br/>'; ?>
1 1 1 1 1
higher than && and || Low
ternary operator
<?php $a = 100; echo $a > 60 ? 'success':'fail'; ?>
success
error suppression operator
<?php echo @(100/0); ?>
The above is the detailed content of PHP basic operators, detailed examples of the difference between single quotes and double quotes. For more information, please follow other related articles on the PHP Chinese website!