工具类函数记录
PHP
shuffle随机打乱数组元素的顺序
$a=[1,2,3,4,5,6,7,8,9,10];
var_dump(shuffle($a));
var_dump($a);
ini_set(‘memory_limit’, -1);//设置内存不限制
在函数执行的时候生效,脚本结束后,设置失效
时间函数相关
microtime — 返回当前 Unix 时间戳和微秒数
//microtime(bool $as_float = false): string|float
//microtime() 返回当前 Unix 时间戳以及微秒数。本函数仅在支持 gettimeofday() 系统调用的操作系统下可用。
//对于性能测量,建议使用 hrtime()。
//默认情况下,microtime() 返回“msec sec”形式的 string,其中 sec 是自 Unix 纪元(格林威治标准时间 1970 年 1 月 1 日 0:00:00)以来的秒数,msec 是自 sec 以来经过的微秒,表示为秒数的小数部分。
//如果 as_float 设置为 true,然后 microtime() 返回 float,表示自 Unix 纪元以来的当前时间,以秒为单位,精确到最接近的微秒。
var_dump(microtime(true));
echo PHP_EOL;echo "\n\r";
var_dump(microtime());
hrtime 【PHP 7 >= 7.3.0, PHP 8】 获取系统的高精度时间
//hrtime(bool $as_number = false): array|int|float|false
//从任意时间点开始统计,返回系统的高精度时间(high resolution time)。 获取的时间戳为单调时间,无法被用户调整。
echo hrtime(true), PHP_EOL;
print_r(hrtime());