php變數的幾種寫法

2021-09-25 06:39:20 字數 1424 閱讀 4100

一、最簡單的

$str = 'hello world!';

二、來個變種

$str = 'good';  

$good = 'test';  

$test = 'hello world!';  

echo $$$str; // hello world!

三、放在引號內的

$str = 'hello world!';  

echo '$str';// $str  

echo "$str";// hello world!

四、list方法來接收

list($a, $b, $c, $d) = array(1, 2, 3, 4);  

echo $a, $b, $c, $d; // 1234

五、界定符

$num = '11';   

$str = 《六、高大上的

$tousername = 'fans';  

$fromusername = 'molaifeng';  

$createtime = time();  

$msgtype = 'text';  

$content = '高大上';  

$texttpl = "%s0

";  

echo sprintf($texttpl, $tousername, $fromusername, $createtime, $msgtype, $content);

php變數什麼情況下加大括號{}如:

$sql = "insert into article (`channel_id`,`title`,`detail`,`pub_time`) values ('','','','');";

不加似乎也可以,加{}是什麼意思呢?

加{}有時候是為了防止變數名和後面的字串連在一起

例如dd

如果$cid=aa

那麼dd=aadd

不加的話你自己看看了$ciddd,豈不變成了ciddd變數了。

php: 字串變數中大括號(花括號{})的作用

php 變數後面加上乙個大括號{},裡面填上數字,就是指 php 變數相應序號的字元。

例如:$str = 'hello';

echo $str; // 輸出為 h

echo $str; // 輸出為 e

如果要檢查某個字串是否滿足多少長度,可以考慮用這種大括號(花括號)加 isset 的方式替代 strlen 函式,因為 isset 是語言結構,strlen 是函式,所以使用 isset 比使用 strlen 效率更高。

比如判斷乙個字串的長度是否小於 5:

if ( !isset ( $str ) ) 就比 if ( strlen ( $str ) < 5 ) 好。

vue中class名為變數的幾種寫法

1 class名只有乙個,只不過是變數 class classname div template export default script 2 通過物件形式 此種方式適合針對固定的class名,判斷是否存在此class名稱 class div template export default scr...

oracle url的幾種寫法

jdbc oracle thin example jdbc oracle thin 注意這裡的格式,後面有 這是與使用sid的主要區別。這種格式是oracle 推薦的格式,因為對於集群來說,每個節點的sid 是不一樣的,但是service name 確可以包含所有節點。jdbc oracle thi...

網頁的幾種寫法

第一種是小白式的寫法,就是先寫html再寫css,一對一的寫法,這種寫法效率比較低下,同樣的 要寫n遍 另外我加一句,img為什麼放多張 的時候會有邊距!這裡的解決辦法是這樣的,可以將img空格刪除掉,如果你用margin left解決掉的時候,到時候再上傳到伺服器中就會發生錯誤,因為上傳到伺服器的...