Blogger Information
Blog 15
fans 0
comment 0
visits 8369
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数据类型及类型转换
我们的关系如此狭窄
Original
520 people have browsed it
<?php
/*
 * 作业内容:1. php变量的8种数据类型?
 *          2. php变量类型的转换?
 *          3. 如何定义php常量, 实例演绎php变量与常量的区别?
 */
/*
 * 四中标量类型
 * boolean(布尔型) integer(整型) float(浮点型)    string(字符串)
 * 两种复合类型
 * array(数组)    object(对象)
 * 两种特殊类型
 * resource(资源) NULL(NULL)
 */

/*
 * gettype(var)
 * is_bool()       判断数据类型是否为boolean
 * is_integer()    判断数据类型是否为integer
 * is_string()     判断数据类型是否为string
 *
 * */
$st = '123.12';
echo  gettype($st); //获取数据类型    string
echo "<br>";
var_dump(is_bool($st)); //     bool(false)
echo "<br>";
var_dump(is_string($st)); // bool(true)
echo "<br>";
/*
 * isset()  判断变量是否设置
 * empty()  判断是否为空
 * */
define('ENV_INT_IP','127.0.0.1');
class DataType{
    const dateTime = '2021/8/4';
    public function getBool($str){
        //通过转换方法boolval转换
        //return boolval($str);
        //通过设置变量类型方法settype转换
        //settype($str,'boolean');
        //return $str;
        return  (boolean)($str);
    }
    public function getInt($str){
        //通过自动运算自动转换
        // return $str - 0;
        //通过转换方法intval转换
        // return intval($str);
        //通过设置变量类型方法settype转换
        //settype($str,'integer');
        //return $str;
        return (integer)($str);
    }
    public function getStr($str){
        // return $str.'';
        //return strval($str);

        //settype($str,'string');
        //return $str;
        return (string)($str);
    }
    public function getFloat($str){
     //   return $str + 0.12;
     //    return floatval($str);

        //settype($str,'float');
        //return $str;
        return (float)($str);
    }
    public function getArr($str){
        //settype($str,'array');
        //return $str;

        return (array)($str);
    }
    public function getObj($str){
//        settype($str,'object');
//        return $str;
        return (object)($str);
    }
    public function getRes($str){
        $res = fopen("1.txt", "rw");
        var_dump($res);
        fclose($res);
    }
    public function getNu($str){
//      settype($str,'null');
//       return $str;
       $str = null;
       return $str;
    }
}
$cl = new DataType();
$str = 123;
$res = $cl->getNu($str);
var_dump($res);
echo "<br>";
echo $cl::dateTime;
echo "<br>";
echo ENV_INT_IP;


Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post