码迷,mamicode.com
首页 > Web开发 > 详细

PHP的数据类型

时间:2016-01-20 15:44:45      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

简介

PHP支持8种基本的数据类型

四种标量类型:

boolen

integer

float(double)

string

两种复合类型:

array

object(对象)

最后是两种特殊类型:

resource(资源)

NULL(NULL)

还有其他的伪类型:

mixed

number

callback

以及伪变量$...

Note:如果想查看某个表达式的值和类型,用 var_dump().

如果只是想得到一个易读懂的类型的表达方式用于调试,用gettype().要判断某个类型,不要用gettype(),而用is_type函数.

 

<?php
    $a_bool =TRUE;//bool
    $a_str1="foo";//string
    $a_str2="foo";//string
    $a_int=12;//integer

    echo gettype($a_bool);//prints out:boolean//注意 不要写成a_bool,前面要加上$
    echo gettype($a_int);//prints out:integer//注意 不要写成a_bool,前面要加上$
    
    /*
     If this is an integer,increment it by four
     */
    if(is_int($a_int))
    {
        $a_int+=4;
        echo $a_int;
    }
    //if $a_bool is a string,print it out
    if(is_string($a_bool))
    {
        echo "String:$a_bool";
    }
?>

如果要将一个变量强制转换为某类型,可以对其使用强制转换或者settype()函数.

 

PHP的数据类型

标签:

原文地址:http://www.cnblogs.com/vegas/p/5145397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!