判斷變數存在
<code><span>isset</span>(<span>$var</span>);<span>//只判断是否有这个变量,变量存在就是 TURE;</span></code>
判斷變數為空
<code>!empty(<span>$var</span>);<span>//</span>“”,<span>0</span>,“<span>0</span>”,<span>NULL</span>,<span>FALSE</span>,array(),var <span>$var</span>; 和没有任何属性的对象在用 empty判断时,都是空的,返回<span>TURE</span>;</code>
判斷是否為false
<code><span>if</span>(<span>0</span> == <span>false</span>){<span>echo</span><span>"true"</span>;} <span>//true</span><span>if</span>(<span>0.0</span> == <span>false</span>){<span>echo</span><span>"true"</span>;} <span>//true</span><span>if</span>(<span>array</span>() == <span>false</span>){<span>echo</span><span>"true"</span>;} <span>//true</span><span>if</span>(<span>"0"</span> == <span>false</span>){<span>echo</span><span>"true"</span>;} <span>//true</span><span>if</span>(<span>''</span> == <span>false</span>){<span>echo</span><span>"true"</span>;} <span>//true</span><span>if</span>(<span>NULL</span> == <span>false</span>){<span>echo</span><span>"true"</span>;} <span>//true</span></code>
靜態變數:駐留記憶體的變數
<code><span><span>function</span><span>a</span><span>()</span>{</span><span>static</span><span>$a</span> = <span>1</span>; <span>echo</span><span>$a</span>; <span>$a</span>++; } a();<span>//1</span> a();<span>//2</span></code>
隨的語言
<code><span><span>define</span></span>(<span>"TEST"</span>,<span>'codekissyoung'</span>); echo TEST;<span>//codekissyoung</span></code>
將assoc 數組拆解成變數
<code><span>$a</span> = <span>"test"</span>; <span>$test</span> = <span>"i am the test"</span>; <span><span>function</span><span>test</span>(){</span><span>echo</span><span>"i am function test!"</span>;} <span>echo</span><span>$a</span>; <span>//test</span><span>echo</span><span>$$a</span>; <span>// i am the test</span><span>$a</span>(); <span>//i am function test!</span></code>
動態new 物件和呼叫函數
<code><span>foreach</span> (<span>$_POST</span><span>as</span><span>$key</span> => <span>$value</span>) { <span>$$key</span> = <span>$value</span>; }</code>
變數的參考
<code><span>//example.com?class=person&func=run</span><span>$class</span>=<span>$_GET</span>[<span>'class'</span>]; <span>$func</span>=<span>$_GET</span>[<span>'func'</span>]; <span>$obj</span>=<span>new</span><span>$class</span>(); <span>$obj</span>-><span>$func</span>();</code>
引用和函數結合使用全域名稱與使用全域版權聲明
知識取之於民,用之於民!歡迎轉載,轉載請開頭附上本文鏈接,不定期更新文章!以上就介紹了php:關於變量,類型,作用域,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。