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;
}