当前位置:Gxlcms > PHP教程 > PHP移动互联网开发笔记(5)——基础函数库_PHP教程

PHP移动互联网开发笔记(5)——基础函数库_PHP教程

时间:2021-07-01 10:21:17 帮助过:7人阅读

一、数学函数库

● floor

舍一取整(向下取整)

float floor (float $value);

");
echo(floor(0.40)."
"); echo(floor(5)."
"); echo(floor(5.1)."
"); echo(floor(-5.1)."
"); echo(floor(-5.9)."
") ?>

\

● ceil

进一取整(向上取整)

float ceil(float $value);

");
echo(ceil(0.40)."
"); echo(ceil(5)."
"); echo(ceil(5.1)."
"); echo(ceil(-5.1)."
"); echo(ceil(-5.9)."
") ?>
\

● max

取最大值

mixed max(mixed $value, mixed $value, ......);

");
echo(max(-3,5)."
"); echo(max(-3,-5)."
"); echo(max(7.25,7.30)."
"); ?>
\

● min

取最小值

mixed min(mixed $value, mixed $value, ......);

");
echo(min(-3,5)."
"); echo(min(-3,-5)."
"); echo(min(7.25,7.30)."
"); ?>
\

● pow

幂运算

number pow(number $base, number $expr);

";
echo pow(6,2)."
"; echo pow(-6,2)."
"; echo pow(-6,-2)."
"; echo pow(-6,5.5)."
"; ?>
\

● sqrt

取平方根

float sqrt(float $arg)

";
echo(sqrt(1))."
"; echo(sqrt(9))."
"; echo(sqrt(0.64))."
"; echo(sqrt(-9))."
"; ?>
\

● rand

产生随机数

int mt_rand(int $min, int max);

";
echo rand(10,100)."
"; ?>
\

● mt_rand

产生一个更好的随机数

int mt_rand(int $min, int max);

和上面的rand用法及输出结果类似,这个比rand快4倍。

● round

四舍五入

float round(float $val [, int $precision=0])

第二个参数可选,规定小数点保留位数

number_format

通过千位分组格式化数字

float number_format(float $number, int $decimals=0, string $dec_point=",', string $thousands_sep=',');

二、日期时间函数库

● time

返回当前Unix时间戳

int time(void);

";
$nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs
echo 'Now:       '. date('Y-m-d') ."
"; echo 'Next Week: '. date('Y-m-d', $nextWeek) ."
"; ?>
\

● date

格式化一个本地时间/日期

string date(string format[, int timestamp]);

● getdate

取得日期/时间信息

array getdate([int timestamp]);

MD5哈希

string md5(string $str[, bool $raw_output=false]);

strpos

返回一个字符在另一个字符第一次出现的位置

int strpos(string haystack, mixed needle[, int offset]);


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/755796.htmlTechArticle一、数学函数库 ● floor 舍一取整(向下取整) float floor (float $value); ");echo(floor(0.40)." ");echo(floor(5)." ");echo(floor(5.1)." ");echo(floor(-5.1)." ");ec...

人气教程排行