Home > php教程 > php手册 > body text

php数据类型02

WBOY
Release: 2016-06-06 19:57:56
Original
1867 people have browsed it

1、php是弱类型语言,不需要定义变量类型 2.可通过getType(变量,常量)得到类型,如下: $a = nihao; echo getType($a); //系统函数不区分大小写gettype()也可以 3.判断数据类型也可以: is_int(),is_float(),is_string(),is_bool() //布尔型命名和其他有点

1、php是弱类型语言,不需要定义变量类型

 

2.可通过getType(变量,常量)得到类型,如下:

   $a  = "nihao";

   echo getType($a);    //系统函数不区分大小写gettype()也可以

 

3.判断数据类型也可以:

      is_int(),is_float(),is_string(),is_bool()   //布尔型命名和其他有点不一样

     is_array(),is_object(),is_resource(),is_null()

      getType()返回字符串,而上面返回boolean类型,因此上面判断函数比getType()更方便我们操作

 

4.遍历数组,注意数据打印加编号写法

   $array = array("1","2","3");
    if(is_array($array)){
          foreach($array as $key => $val){
         echo $key."=".$val."";
      }
    }else {
           echo "this is not a array";
    }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!