php-系统常用函数


1、有关输出的函数

  • print():类似于echo输出,本质是一种结构(可以不使用括号),不是函数,返回值为1

  • print_r():类似于var_dump,但比它简单,不会输出数据的类型,只会输出值

 1 示例:
 2 <?php
 3     echo print('hello world');
 4     print 'hello world';
 5     $a='hello world';
 6     print_r($a);
 7 ?>
 8 //结果:hello world
 9        1helloworld    //1:echo print()
10        hello world

 

 

2、有关时间的函数

  • date()

    按照指定格式对应的时间戳(从1970年格林统治时间开始计算的秒数),如果没有指定特定的时间戳,那么就是默认解释当前的时间戳

  • time()

    获取当前时间对应的时间戳(返回1970年1月1日00:00:00到当前时间的秒数)

  • microtime()

    获取当前量秒级别的时间

  • strtotime()

    按照规定格式的字符串转换乘时间戳

 1 示例:
 2 <?php
 3     echo date('y 年 m 月 d 日 H:i:s',12345678);
 4     echo time(),'</br>';    //</br>换行
 5     echo microtime 6     echo strtotime('tomorrow 10 hours')
 7 ?>
 8 
 9 //结果:
10 1970年05月24 05:21:18
11 1494913599
12 0.76953200 1494913599
13 1494986400

 

 

3、有关数学的函数

  • max():返回参数中最大的值

  • min():返回参数中最小的值

  • rand():返回一个随机值

    rand(5,15):返回5到15之间的随机数

  • mt_rand():与rand一样,只是底层结构不一样,效率比rand高(建议使用)

  • round():四舍五入

  • ceil():向上取整

  • floor():向下取整

  • pow():求指定数字的指定指数次结果

    pow(2,8)==2^8==256

  • abs():求绝对值

  • sqrt():求平方根

 

4、有关函数的函数

  • function_exists():判断指定函数名字是否在内存中存在(帮助用户不去使用一个不存在的代码,让代码安全性更高)

  • func_get_arg():在自定义函数中获取指定数值对应的参数

  • func_get_args():在自定义函数中获取所有的参数(数组)

  • func_num_args():获取当前自定义函数的参数数量

 1 function test($a,$b){
 2     //获取指定参数
 3     var_dump(func_get_arg(1));
 4     //获取所有参数
 5     var_dump(func_get_args());
 6     //获取参数数量
 7      var_dump(func_gnum_args());
 8 }
 9 //调用函数
10  function_exists('test') && test(1,'2',3,4);

 

posted @ 2020-09-08 11:31  山鬼不识字  阅读(99)  评论(0编辑  收藏  举报