php学习代码传记

WBOY
Release: 2016-06-13 12:28:47
Original
908 people have browsed it

php学习代码杂记

16/2/22

字符串连接

(1)连接运算符(“.”):它返回将右参数附加到左参数后面所得的字符串。

(2)连接赋值运算符(“.=”):它将右边参数附加到左边的参数后。

相当于JS里面的 += 。

        <span style="color: #800080;">$b</span> = "东边日出西边雨"<span style="color: #000000;">;        </span><span style="color: #800080;">$b</span> .= ",道是无晴却有晴"<span style="color: #000000;">;        </span><span style="color: #800080;">$c</span> = "东边日出西边雨"<span style="color: #000000;">;        </span><span style="color: #800080;">$c</span> = <span style="color: #800080;">$c</span>.",道是无晴却有晴"<span style="color: #000000;">;    </span><span style="color: #0000ff;">echo</span>  <span style="color: #800080;">$b</span>."<br>";<span style="color: #008000;">//</span><span style="color: #008000;">东边日出西边雨,道是无晴却有晴</span>    <span style="color: #0000ff;">echo</span>  <span style="color: #800080;">$c</span>."<br>";<span style="color: #008000;">//</span><span style="color: #008000;">东边日出西边雨,道是无晴却有晴</span>
Copy after login

 

 

 

赋值运算

$a = "cmflovehxc";
$b=$a;
$c=&$a;
$a = "hxclovecmf";

echo $b."
";
echo $c;

 

(1)“=”:把右边表达式的值赋给左边的运算数。它将右边表达式值复制一份,交给左边的运算数。换而言之,首先给左边的运算数申请了一块内存,然后把复制的值放到这个内存中。

相当于JS的等于号。变量赋值;两个变量是两个不同的堆内存。

(2)“=&”:引用赋值,意味着两个变量都指向同一个数据。它将使两个变量共享一块内存,如果这个内存存储的数据变了,那么两个变量的值都会发生变化。

两个变量是两个相同的堆内存。

 

常量

<span style="color: #008080;"> 1</span> <span style="color: #008080;">define</span>("PI1",3.14<span style="color: #000000;">);</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$p</span> = "PI1"<span style="color: #000000;">;</span><span style="color: #008080;"> 3</span> <span style="color: #0000ff;">echo</span> <span style="color: #800080;">$p</span>;<span style="color: #008000;">//</span><span style="color: #008000;">PI1</span><span style="color: #008080;"> 4</span> <span style="color: #0000ff;">echo</span> <span style="color: #008080;">constant</span>(<span style="color: #800080;">$p</span>);<span style="color: #008000;">//</span><span style="color: #008000;">3.14</span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">defined</span>(<span style="color: #800080;">$p</span>)==<span style="color: #0000ff;">true</span><span style="color: #000000;">){</span><span style="color: #008080;"> 6</span>  <span style="color: #0000ff;">echo</span> '111'<span style="color: #000000;">  ; </span><span style="color: #008080;"> 7</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;"> 8</span>  <span style="color: #0000ff;">echo</span> '222'<span style="color: #000000;">;</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">}</span><span style="color: #008080;">10</span> <span style="color: #008000;">//</span><span style="color: #008000;">返回111<br>11 //constant()与defined()都有一种翻译功能<br></span>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template