Android programmers learn PHP development (6)-String array object resources-PhpStorm

黄舟
Release: 2023-03-06 09:48:01
Original
1149 people have browsed it

var_dump()方法真好用。
简单地说,var_dump()方法会返回变量的数据类型和值。
复杂点说,var_dump()方法是判断一个变量的类型与长度,并输出变量的数值,如果变量有值输的是变量的值并回返数据类型.此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。


<?php
    /**
     * 变量类型
     * 字符串String
     * 顺带介绍转义字符
     */
    $int = 10; // 打印结果:10
    $str2 = "a"; // 打印结果:a
    $str3 = "this is a &#39;demo&#39;"; // 打印结果:this is a &#39;demo&#39;
    $str4 = "this is a \"demo\""; // 打印结果:this is a "demo"
    $str5 = "this is a $int"; // 打印结果:this is a 10
    $str6 = &#39;this is a $int&#39;; // 打印结果:this is a $int
    //$str7 = "this is a $intttttt"; // 打印结果:会报错 , 因为没有这个变量
    $str8 = "this is a {$int}ttttt,\\,\n,\r,\t"; // 打印结果:this is a 10ttttt,\, , ,
    $str9 = &#39;this is a {$int}ttttt,\\,\n,\r,\t&#39;; // 打印结果:this is a {$int}ttttt,\,\n,\r,\t
    $str10 = <<<hello
        <<<是定界字符串的内容,这里面随便写.....$int 出现 hello; 也不怕,因为需要顶格写,才表示结束
hello;
    // 打印结果:<<<是定界字符串的内容,这里面随便写.....10 出现 hello; 也不怕,因为需要顶格写,才表示结束

    /**
     * 变量类型
     * 数组Array
     */
    $arr = array(1,2,3,4,5); // array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) }

    /**
     * 对象
     * Object
     */
    class Person{
        var $name;
        var $age;
        var $sex;
        function say(){

        }
        function eat(){

        }
    }
    $person = new Person(); // object(Person)#1 (3) { ["name"]=> NULL ["age"]=> NULL ["sex"]=> NULL }
    $person2 = new Person(); // object(Person)#2 (3) { ["name"]=> NULL ["age"]=> NULL ["sex"]=> NULL }

    /**
     * 资源
     * ok.txt需要放在当前php所在目录下
     * 如果文本中的内容是中文编码格式请使用UTF-8
     * 在txt另存的时候可以看到编码选项
     */
    $file = fopen("ok.txt","r"); // 现在显示的是ok.txt的内容
//    if (NULL=="ok.txt"){
//        printf("不存在<br>");
//    }else{
//        printf("存在<br>");
//    }

    echo $int;
    echo "<br>";
    echo $str2;
    echo "<br>";
    echo $str3;
    echo "<br>";
    echo $str4;
    echo "<br>";
    echo $str5;
    echo "<br>";
    echo $str6;
    echo "<br>";
    //echo $str7;
    echo "<br>";
    echo $str8;
    echo "<br>";
    echo $str9;
    echo "<br>";
    echo $str10;
    echo "<br>";
    var_dump($arr);
    echo "<br>";
    var_dump($person);
    echo "<br>";
    var_dump($person2);
    echo "<br>";
    echo fread($file,filesize("ok.txt"));
    echo "<br>";
    fclose($file); // 释放资源
Copy after login

 以上就是Android程序员学PHP开发(6)-字符串数组对象资源-PhpStorm 的内容,更多相关内容请关注PHP中文网(www.php.cn)!



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 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!