16/2/22
字符串连接
(1)连接运算符(“.”):它返回将右参数附加到左参数后面所得的字符串。
(2)连接赋值运算符(“.=”):它将右边参数附加到左边的参数后。
相当于JS里面的 += 。
<span>$b</span> = "东边日出西边雨"<span>; </span><span>$b</span> .= ",道是无晴却有晴"<span>; </span><span>$c</span> = "东边日出西边雨"<span>; </span><span>$c</span> = <span>$c</span>.",道是无晴却有晴"<span>; </span><span>echo</span> <span>$b</span>."<br />";<span>//</span><span>东边日出西边雨,道是无晴却有晴</span> <span>echo</span> <span>$c</span>."<br />";<span>//</span><span>东边日出西边雨,道是无晴却有晴</span>
赋值运算
$a = "cmflovehxc";
$b=$a;
$c=&$a;
$a = "hxclovecmf";
echo $b."
";
echo $c;
(1)“=”:把右边表达式的值赋给左边的运算数。它将右边表达式值复制一份,交给左边的运算数。换而言之,首先给左边的运算数申请了一块内存,然后把复制的值放到这个内存中。
相当于JS的等于号。变量赋值;两个变量是两个不同的堆内存。
(2)“=&”:引用赋值,意味着两个变量都指向同一个数据。它将使两个变量共享一块内存,如果这个内存存储的数据变了,那么两个变量的值都会发生变化。
两个变量是两个相同的堆内存。
常量
<span> 1</span> <span>define</span>("PI1",3.14<span>); </span><span> 2</span> <span>$p</span> = "PI1"<span>; </span><span> 3</span> <span>echo</span> <span>$p</span>;<span>//</span><span>PI1</span> <span> 4</span> <span>echo</span> <span>constant</span>(<span>$p</span>);<span>//</span><span>3.14</span> <span> 5</span> <span>if</span>(<span>defined</span>(<span>$p</span>)==<span>true</span><span>){ </span><span> 6</span> <span>echo</span> '111'<span> ; </span><span> 7</span> }<span>else</span><span>{ </span><span> 8</span> <span>echo</span> '222'<span>; </span><span> 9</span> <span>} </span><span>10</span> <span>//</span><span>返回111<br />11 //constant()与defined()都有一种翻译功能<br /></span>