知识屋:更实用的电脑技术知识网站
所在位置:首页 > 编程技术 > PHP编程

PHP移动互联网开发笔记(5)――基础函数库

发布时间:2014-09-05 10:14:08作者:知识屋

一、数学函数库

● 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; 60secsecho '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]);


(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜