⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.operators.assignment.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Assignment Operators</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.operators.arithmetic.html">Arithmetic Operators</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.operators.bitwise.html">Bitwise Operators</a></div> <div class="up"><a href="language.operators.html">Operators</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="language.operators.assignment" class="sect1">   <h2 class="title">Assignment Operators</h2>   <p class="simpara">    The basic assignment operator is &quot;=&quot;. Your first inclination might    be to think of this as &quot;equal to&quot;. Don&#039;t. It really means that the    left operand gets set to the value of the expression on the    rights (that is, &quot;gets set to&quot;).   </p>   <p class="para">    The value of an assignment expression is the value assigned. That    is, the value of &quot;$a = 3&quot; is 3. This allows you to do some tricky    things:     <div class="informalexample">     <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$a&nbsp;</span><span style="color: #007700">=&nbsp;(</span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">)&nbsp;+&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;$a&nbsp;is&nbsp;equal&nbsp;to&nbsp;9&nbsp;now,&nbsp;and&nbsp;$b&nbsp;has&nbsp;been&nbsp;set&nbsp;to&nbsp;4.<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>    </div>   </p>   <p class="para">    In addition to the basic assignment operator, there are &quot;combined    operators&quot; for all of the <a href="language.operators.html" class="link">binary    arithmetic</a>, array union and string operators that allow you to use a value in an    expression and then set its value to the result of that expression. For    example:    <div class="informalexample">     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">+=&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;sets&nbsp;$a&nbsp;to&nbsp;8,&nbsp;as&nbsp;if&nbsp;we&nbsp;had&nbsp;said:&nbsp;$a&nbsp;=&nbsp;$a&nbsp;+&nbsp;5;<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$b&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"There!"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;sets&nbsp;$b&nbsp;to&nbsp;"Hello&nbsp;There!",&nbsp;just&nbsp;like&nbsp;$b&nbsp;=&nbsp;$b&nbsp;.&nbsp;"There!";<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>    </div>   </p>   <p class="para">    Note that the assignment copies the original variable to the new    one (assignment by value), so changes to one will not affect the    other. This may also have relevance if you need to copy something    like a large array inside a tight loop. Assignment    by reference is also supported, using the <span class="computeroutput">$var =    &amp;$othervar;</span> syntax.    &#039;Assignment by reference&#039; means that both variables end    up pointing at the same data, and nothing is copied anywhere.     To learn more about references, please read <a href="language.references.html" class="link">References explained</a>. As of     PHP 5, objects are assigned by reference unless explicitly told     otherwise with the new <a href="language.oop5.cloning.html" class="link">clone</a>     keyword.   </p>  </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.operators.arithmetic.html">Arithmetic Operators</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.operators.bitwise.html">Bitwise Operators</a></div> <div class="up"><a href="language.operators.html">Operators</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -