PHP学习笔记(十二)

逻辑运算符

对布尔类型进行运算

  • and或者&&(逻辑与)

  • or或者||(逻辑或)

  • xor(逻辑异或)

  • !(逻辑非)

其他运算符

  • ?
    格式:表达式一?表达式二:表达式三;
    如果表达式一为3true,则执行表达式二,否则则执行表达式三

  • ``
    可以把系统命令放在里面执行

自定义函数

系统自带的

  • func_get_args()
    将参数转化为数组

        <?php
      $pass=60;
      $a=40;
      function test(){
          var_dump(func_get_args());
      }
      $i=2;
      test(21,21,21);
    
      输出为
      D:\wamp64\www\demo1\index.php:5:
      array (size=3)
        0 => int 21
        1 => int 21
        2 => int 21
      ?>
    
  • func_get_arg()

    这位更是重量级,可以获取数组指定位置的数据,只需要在括号内填入数字,即可获得对应数字上的数组上的数据

  • func_num_args()
    返回所在自定义函数传入函数的参数个数

可变函数

当面ntr太强了

function test1(){
    echo '我是test1';
}
$a='test1';
$a();

递归函数

function test2($n){
    echo $n.'<br />';
    if($n>0){
        test2($n-1);
    }else {
        echo '------<br />';
    }
    echo $n.'<br />';
}
test2(3);
输出为
3
2
1
0
------
0
1
2
3
posted @ 2021-08-15 16:57  Emuaer  阅读(31)  评论(0编辑  收藏  举报