zoukankan      html  css  js  c++  java
  • PHP基本类型操作

    //关键字对大小写不敏感
    echo ('hello world!<br>');
    ECho ('hello world<br>');
    eCho ('hello world<br>');
    */
    /*
    //请把变量视为存储数据的容器。
    $x = 5;
    $y = 6;
    $z = $x + $y;
    echo ($z);
    */
    /*
    //变量对大小写敏感
    $color = 'red';
    echo ('my car is '.$color.'<br>');
    echo ('my house is '.$COLORr.'<br>');
    echo ('my boat is '.$coLOR.'<br>');
    */
    /*
    $txt = 'hello world';
    $x = 5;
    $y = 10.5;
    echo ($txt.'<br>'.$x.'<br>'.$y);
    */
    /*
    //全局变量只能用在函数外,局部变量只能用在函数内,否则未定义.
    $x = 5;
    function myTest(){
    $y = 10;
    echo ("<p>测试函数内部的变量:</p>");
    echo ("变量 x 是: $x");
    echo ('<br>');
    echo ("变量 y 是: $y");
    }
    myTest();

    echo ('<p>测试函数内部的变量:</p>');
    echo ("变量 x 是: $x");
    echo ('<br>');
    echo ("变量 y 是: $y");
    */
    /*
    //想要访问全局变量必须在全局变量前加global.
    $x = 10;
    $y = 10;
    function myTest(){
    global $x,$y;
    $y = $x + $y;
    }
    myTest();
    echo ($y);
    */

    /*
    //$GLOBALS[index] 数组 index就是变量名.$GLOBALS[index]可以存储所有的全局变量
    $x = 5;
    $y = 10;

    function myTest(){
    $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
    }
    myTest();
    echo ($y);
    */
    /*
    //static 静态变量 修饰的变量值为最后一次赋值.在函数内定义就为局部变量,在函数外即为全局变量.
    function myTest(){
    static $x = 0;
    echo ($x.'<br>');
    $x++;
    }
    myTest();
    myTest();
    myTest();
    */

    /*
    //echo - 能够输出一个以上的字符串
    //print - 只能输出一个字符串,并始终返回 1
    echo ('<h2>PHP is fun!</h2>');
    echo ('hello world!<br>');
    echo ("I'am about to learn PHP!<br>");
    echo "this","string","was","made","with multiple parameters.";
    */
    /*
    $txt1 = 'learn PHP';
    $txt2 = 'w3shool.com.con';
    $cars = array("Volvo","BMW","SAAB");
    echo ($txt1.'<br>');
    echo ("Student PHP at $txt2.<br>");
    echo ("My car is a {$cars[1]}");
    */
    /*
    print ("<h2>PHP is fun!</h2>");
    print ('hello world!<br>');
    print ("I'm about to learn PHP!");
    */
    /*
    $txt = 'Learn PHP';
    $txt1 = 'w3shool.com.cn';
    $cars = array("VOlovo","BMW","SAAB");
    print ($txt.'<br>');
    print ("Stident PHP at $txt1<br>");
    print ("my car is a {$cars[2]}");
    */
    /*
    //PHP的字符串
    $x = 'hello world!';
    echo ($x.'<br>');
    $x = 'hello world!';
    echo ($x);
    */
    /*
    //整数
    //整数必须有至少一个数字(0-9)
    //整数不能包含逗号或空格
    //整数不能有小数点
    //整数正负均可
    //可以用三种格式规定整数:十进制、十六进制(前缀是 0x)或八进制(前缀是 0)
    //var_dump() 会返回变量的数据类型和值
    $x = 555;
    var_dump($x);
    $x = -668;
    var_dump($x);
    $x = 0x8c;
    var_dump($x);
    $x = 066;
    var_dump($x);
    */
    /*
    //浮点型
    $x = 10.123;
    var_dump($x);
    $x = 2.4e3;
    var_dump($x);
    $x = 8E-5;
    var_dump($x);
    */
    /*
    //false为空
    $x =true;
    $y = false;
    echo ($x.'<br>');
    echo ($y);
    */
    /*
    $cars = array("vovlo","nhnh","nihgsk");
    var_dump($cars);
    */
    /*
    对象是存储数据和有关如何处理数据的信息的数据类型。
    在 PHP 中,必须明确地声明对象。
    首先我们必须声明对象的类。对此,我们使用 class 关键词。类是包含属性和方法的结构。
    然后我们在对象类中定义数据类型,然后在该类的实例中使用此数据类型:
    */
    /*
    class Car
    {
    var $color;
    function Car($color='green'){
    $this->color = $color;
    }
    function what_color(){
    return $this->color;
    }
    }
    */
    /*
    特殊的 NULL 值表示变量无值。NULL 是数据类型 NULL 唯一可能的值。
    NULL 值标示变量是否为空。也用于区分空字符串与空值数据库。
    可以通过把值设置为 NULL,将变量清空:
    */
    /*
    $x = 'hello world';
    $x = null;
    var_dump($x);
    */
    /*
    //字符串函数strlen字符长度
    echo (strlen("hello world!"));
    */
    /*
    //strpos() 函数用于检索字符串内指定的字符或文本
    echo (strpos("hello world!","hel"));
    */
    //常量贯穿整个脚本是自动全局的 常量名称前面没有 $ 符号
    /*请使用 define() 函数 - 它使用三个参数:
    首个参数定义常量的名称
    第二个参数定义常量的值
    可选的第三个参数规定常量名是否对大小写敏感。默认是 false。
    */
    //对大小写敏感
    /*
    define("lisi","45");
    echo (Lisi);
    */
    //对大小写敏感
    /*
    define("lisi","45",true);
    echo (Lisi);
    */
  • 相关阅读:
    测试数据生成利器
    9.22“月饼杯”递归算法欢乐赛测试报告总结
    lemon评测软件配置使用方法
    1200:分解因数
    大犇博客
    C++ |递归原理与构造技巧
    2018.9.8信息奥赛集训评测报告总结
    1195 判断整除
    计算机图形学初步
    AcWing
  • 原文地址:https://www.cnblogs.com/wujie123/p/5335004.html
Copyright © 2011-2022 走看看