2014年10月12日

PHP的8种变量类型的介绍

PHP支持八种原始类型 — var_dump()
– 四种标量类型:
布尔型(boolean)
正型(interger)
浮点型(float) (浮点数,也作double)
字符串(string)

-两种复合类型:
数组(Array)
对象(Object)

-最后两种特殊类型
资源(Resource)
Null

<?php
          echo "以下4种标量:<br>";

          $var = true;
          
          var_dump($var);   //boolean
          echo "<br>";
          
          $var = 10;
          
          var_dump($var);     //int
          echo "<br>";
          
          $var = 10.12;
          
          var_dump($var);      //float
          echo "<br>";

          $var = "hello world";
          
          var_dump($var);       //string
          echo "<br>";
          
          echo "以下是两种复合类型:<br>";
          $var = array("one","two","three");
          
          var_dump($var);     //array
          echo "<br>";
          
          class Demo{
                    var $one = 10;
                    var $two = 20;
                    var $three =30;                    
               }
          
          $var = new Demo;
          
          var_dump($var);  //object
          echo "<br>";
          
          echo "以下是两种特殊类型:<br>";
          
          $var = mysql_connect("localhost","root","");
          
          var_dump($var);  //resource
          echo "<br>";
          
          $var = null;
          
          var_dump($var);  //NULL