zoukankan      html  css  js  c++  java
  • php基础_变量和比较符

    本人php菜鸟一枚,初读《php和mysql web开发》,把其中的比较基础的一些东西列举出来,方便和自己一样的菜鸟快速入门,并且方便自己以后复习理解。

    ①变量

      1.比较有特色的应该是变量不需要预定义,可以直接使用。

      2.变量放在单引号和双引号中的作用是完全不一样的

    1 <?php
    2         $test = 'myString';
    3         echo '$test.------';
    4         echo "$test.------";
    5 ?>

      显示结果如下

      

      结论:变量在双引号内才能被识别,在单引号内只能被当做字符串

      3.字符串连接用【.】($aaa = $bbb.$ccc)

      4.常量(属于变量的一部分吧)

        常量和变量在定义时候有一个明显的不同就是【$】符号的使用

        例如

          define('aaa','aString') // 常量

               $aaa = 'aString' //变量

     ②比较符号

      1.==(等价)

        说明:

        变量:数值相等即可。

        数组:包含相同元素即可。 

     1 <?php
     2         $test1 = '111';
     3         $test2 = 111;
     4         $test3 = array(111,222,333);
     5         $test4 = array ('222','111','333');
     6         $test5 = array('test1'=>'111','test2'=>'222','test3'=>'333');
     7         $test6 = array('test1'=>111,'test2'=>222,'test3'=>333);
     8         if ($test1==$test2) { echo 'success1';}
     9         if ($test3==$test4) { echo 'success2';}
    10         if ($test5==$test6) { echo 'success3';}
    11 ?>

        输出结果:success1success3

      2.===(恒等)

        变量:数值和数据类型都相等

        数组:包含相同的顺序和类型

    <?php
            $test1 = '111';
            $test2 = 111;
            $test3 = array(111,222,333);
            $test4 = array ('111','222','333');
            $test5 = array('test1'=>'111','test2'=>'222','test3'=>'333');
            $test6 = array('test1'=>111,'test2'=>222,'test3'=>333);
            $test7 = array('test3'=>'333','test2'=>'222','test1'=>'111');
            $test8 = array('test1'=>'111','test2'=>'222','test3'=>'333');
            if ($test1===$test2) { echo 'success1';}
            if ($test3===$test4) { echo 'success2';}
            if ($test5===$test6) { echo 'success3';}
            if ($test5===$test7) { echo 'success4';}
            if ($test5===$test8) { echo 'success5';}
    ?>

        输出结果:success5

      3.0和非0

        非0为true,0为false

    <?php
            $test1 = '0';
            $test2 = 1;
            if ($test1) { echo 'success1';}
            if ($test2) { echo 'success2';}
    ?>

        输出结果:success2(在用==做判断时候切记别少写了等号,写成$test1 = '0'

    ③结构

      1.分支 (elseif之间没有空格)

    if (condition1) {
    
    } elseif (condition2) {
    
    } else {
    
    }

        

      

  • 相关阅读:
    64位win2008下IIS未开启32位支持导致DLL无法加载问题
    多控制器传递不同类型实体类到共用视图方案
    敏捷开发学习笔记——产品经理
    一些Razor语法
    敏捷开发学习笔记——用户故事与多职能团队
    UM九图
    Linq的分页
    easyUI datagrid 前端真分页
    C#项目的生成事件及批处理文件
    子类复制父类的值
  • 原文地址:https://www.cnblogs.com/xiaoyezi/p/4094453.html
Copyright © 2011-2022 走看看