php的單引號 雙引號
php
」 」 雙引號裏面的字段會通過編譯器解釋,而後再看成HTML代碼輸出。
‘ ‘ 單引號裏面的不進行解釋,直接輸出。shell
$var = 'test'; echo "var is equal to $var<br>"; echo 'var is equal to $var<br>'; echo "\$var is equal to $var<br>"; echo '\$var is equal to $var<br>';
php的if
數組
if爲真的條件是非0 非空字符牀或非nullui
$var = array(); if($var){ echo "變量爲真"; } if(isset($var)){ echo "變量存在";
range方法能夠返回必定範圍內數字數組
spa
$ac = range(1, 10); $ad = range(1, 10, 3); var_dump($ac); var_dump($ad);
explode code
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6" ; $pieces = explode ( " " , $pizza ); echo $pieces [ 0 ]."<br>"; // piece1 echo $pieces [ 1 ]."<br>"; // piece2 $data = "foo:*:1023:1000::/home/foo:/bin/sh" ; list( $user , $pass , $uid , $gid , $gecos , $home , $shell ) = explode ( ":" , $data ); echo $user."<br>"; // foo echo $pass."<br>"; // * $str = 'one|two|three|four' ; // 正數的 limit var_dump( explode ( '|' , $str , 2 )); // 負數的 limit(自 PHP 5.1 起) var_dump( explode ( '|' , $str , -1 ));
implodethree
$array = array( 'lastname' , 'email' , 'phone' ); $comma_separated = implode ( "," , $array ); echo $comma_separated ; // lastname,email,phone
php變量編譯器
const name = "const"; $name = "value"; function name(){ echo name; } echo name; name();