----- 005-data_type.php -----
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5 <title>一个PHP网页</title> 6 </head> 7 <body> 8 <?php 9 $a = "55"; 10 echo '$a = "55"数据类型是:', gettype($a), '<br/>'; 11 $b = 55; 12 echo '$b = 55数据类型是:', gettype($b), '<br/>'; 13 settype($b, "object"); 14 echo 'settype($b, "object")数据类型是:', gettype($b), '<br/>'; 15 $c = "字符串"; 16 $c_obj = (object)$c; 17 print '$c_obj->scalar= '.$c_obj->scalar."<br/><br/>"; 18 19 #三种数组定义 20 $sheep[0] = '喜羊羊'; 21 $sheep[1] = '灰太狼'; 22 $bear = array("熊大", "熊二"); 23 $sunset = array("暮光之城1"=>"暮色", "暮光之城2"=>"新月", "暮光之城3"=>"月食", "暮光之城4"=>array(1=>'破', 2=>'晓')); 24 25 var_dump($sheep);echo "<br/>"; 26 echo '$sheep[0] = "喜羊羊"数据类型是:', gettype($sheep), '<br/>'; 27 print_r($bear); print "<br/>"; 28 print_r($sheep); print "<br/>"; 29 print_r($sunset); print "<br/><br/>"; 30 31 //测试对象 32 class Hello 33 { 34 function hi($what) 35 { 36 echo "Hello ", $what, " !"; 37 } 38 } 39 (new Hello)->hi("World"); 40 ?> 41 </body> 42 </html>