var_dump()方法真好用。
簡單地說,var_dump()方法會返回變數的資料類型和值。
複雜點說,var_dump()方法是判斷一個變數的類型與長度,並輸出變數的數值,如果變數有值輸的是變數的值並回返資料類型.此函數顯示關於一個或多個運算式的結構資訊,包括運算式的類型與值。數組將遞迴展開值,通過縮排顯示其結構。
<?php /** * 變數類型 * 字串String * 順帶介紹逸出字元 */ $int = 10; // 列印結果:10 $str2 = "a"; // 列印結果:a $str3 = "this is a 'demo'"; // 列印結果:this is a 'demo' $str4 = "this is a \"demo\""; // 列印結果:this is a "demo" $str5 = "this is a $int"; // 列印結果:this is a 10 $str6 = 'this is a $int'; // 列印結果:this is a $int //$str7 = "this is a $intttttt"; // 列印結果:會報錯 , 因為沒有這個變數 $str8 = "this is a {$int}ttttt,\\,\n,\r,\t"; // 列印結果:this is a 10ttttt,\, , , $str9 = 'this is a {$int}ttttt,\\,\n,\r,\t'; // 列印結果:this is a {$int}ttttt,\,\n,\r,\t $str10 = <<<hello <<<是定界字串的內容,這裡面隨便寫.....$int 出現 hello; 也不怕,因為需要頂格寫,才表示結束hello; // 列印結果:<<<是定界字串的內容,這裡面隨便寫.....10 出現 hello; 也不怕,因為需要頂格寫,才表示結束 /** * 變數類型 * 數組Array */ $arr = array(1,2,3,4,5); // array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) } /** * 對象 * Object */ class Person{ var $name; var $age; var $sex; function say(){ } function eat(){ } } $person = new Person(); // object(Person)#1 (3) { ["name"]=> NULL ["age"]=> NULL ["sex"]=> NULL } $person2 = new Person(); // object(Person)#2 (3) { ["name"]=> NULL ["age"]=> NULL ["sex"]=> NULL } /** * 資源 * ok.txt需要放在當前php所在目錄下 * 如果文本中的內容是中文編碼格式請使用UTF-8 * 在txt另存的時候可以看到編碼選項 */ $file = fopen("ok.txt","r"); // 現在顯示的是ok.txt的內容// if (NULL=="ok.txt"){// printf("不存在<br>");// }else{// printf("存在<br>");// } echo $int; echo "<br>"; echo $str2; echo "<br>"; echo $str3; echo "<br>"; echo $str4; echo "<br>"; echo $str5; echo "<br>"; echo $str6; echo "<br>"; //echo $str7; echo "<br>"; echo $str8; echo "<br>"; echo $str9; echo "<br>"; echo $str10; echo "<br>"; var_dump($arr); echo "<br>"; var_dump($person); echo "<br>"; var_dump($person2); echo "<br>"; echo fread($file,filesize("ok.txt")); echo "<br>"; fclose($file); // 釋放資源
以上就是Android程式員學PHP開發(6)-字串數組對象資源-PhpStorm 的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!