首页 > 代码库 > 后盾网PHP第八课

后盾网PHP第八课

运算符
运算符是用来对数值和变量进行某种操作运算的符号。

1.算术运算符        2.递增/递减运算符
3.比较运算符        4.逻辑运算符

5.位运算符        6.其他运算符

<?php
/*
        PHP中的运算符类型:
                1:算术运算符
                2:递增/递减运算符
                3:比较运算符
                4:逻辑运算符
                5:位运算符
                6:其它运算符
*/
/*1:算术运算符
$a = 100;
$b = 200;
$c = $a + $b;
$d = $c-300;
$e = $c*2;
$f = $e/3;
$g = 5%3;
echo ‘$c=‘.$c.‘
$d=‘.$d.‘
$e=‘.$e.‘
$f=‘.$f.‘
5/3的余数是:‘.$g;
*/
/*
        2:递增/递减运算符
                $a = $a+1;
                $a+=1;
                $a++;
                ++$a;
                --$a;
                $a--;
                $a = 1;
                $c = 10 + $a++;
                echo "<h1>\$a = ".$a."</h1>";
                echo "<h1>\$c = ".$c."</h1>";
                echo "-----------------------------------";
                $a = 1;
                $c = 10 + ++$a;
                echo "<h1>\$a = ".$a."</h1>";
                echo "<h1>\$c = ".$c."</h1>";
*/
/*
        3:比较运算符
                > 大于   <小于  >=大于等于  <=小于等于    
                <> != 不等于   !==不全等于   ==等于   ===全等于
*/
$a = 2;
$b = ‘2‘;

var_dump($a !== $b);




<?php

$a = 1;
$user_arr= array("admin","tt","houdunwang","bbs");
$upwd_arr = array("admin"=>"123456","tt"=>"555","houdunwang"=>"888","bbs"=>"999");
$uname = isset($_GET[‘uname‘])?$_GET[‘uname‘]:‘‘;
$upwd = isset($_GET[‘upwd‘])?$_GET[‘upwd‘]:‘‘;
if(in_array($uname,$user_arr)){
        if($upwd == $upwd_arr[$uname]){
                echo "登录成功,可以进行后台操作";
                $ok = true;
        }else{
                echo ("密码错误");
        }
}else{

                echo ("用户名不存在");
}
?>
<html>
        <head>
        </head>
        <body>
<?php
if($ok){
                echo "欢迎来到网站后台";
}else{
        ?>


                <form method="get" action="">
                        用户名:<input type="text" name="uname"/>

                        密码:<input type="text" name="upwd"/>

                        <input type="submit" value="http://www.mamicode.com/会员登录"/>
                </form>

<?php }?>
        </body>
</html>


后盾网PHP第八课