小标
2018-07-12
来源 :
阅读 1561
评论 0
摘要:本文主要向大家介绍了PHP语言大牛开发笔记(5)——基础函数库,通过具体的实例向大家展示,希望对大家学习php语言有所帮助。
本文主要向大家介绍了PHP语言大牛开发笔记(5)——基础函数库,通过具体的实例向大家展示,希望对大家学习php语言有所帮助。
一、数学函数库
● floor
舍一取整(向下取整)
float floor (float $value);
[php] view plain copy
1. <?php
2. echo(floor(0.60)."<br>");
3. echo(floor(0.40)."<br>");
4. echo(floor(5)."<br>");
5. echo(floor(5.1)."<br>");
6. echo(floor(-5.1)."<br>");
7. echo(floor(-5.9)."<br>")
8. ?>
● ceil
进一取整(向上取整)
float ceil(float $value);
[php] view plain copy
1. <?php
2. echo(ceil(0.60)."<br>");
3. echo(ceil(0.40)."<br>");
4. echo(ceil(5)."<br>");
5. echo(ceil(5.1)."<br>");
6. echo(ceil(-5.1)."<br>");
7. echo(ceil(-5.9)."<br>")
8. ?>
● max
取最大值
mixed max(mixed $value, mixed $value, ......);
[php] view plain copy
1. <?php
2. echo(max(5,7)."<br>");
3. echo(max(-3,5)."<br>");
4. echo(max(-3,-5)."<br>");
5. echo(max(7.25,7.30)."<br>");
6. ?>
● min
取最小值
mixed min(mixed $value, mixed $value, ......);
[php] view plain copy
1. <?php
2. echo(min(5,7)."<br>");
3. echo(min(-3,5)."<br>");
4. echo(min(-3,-5)."<br>");
5. echo(min(7.25,7.30)."<br>");
6. ?>
● pow
幂运算
number pow(number $base, number $expr);
[php] view plain copy
1. <?php
2. echo pow(4,2)."<br>";
3. echo pow(6,2)."<br>";
4. echo pow(-6,2)."<br>";
5. echo pow(-6,-2)."<br>";
6. echo pow(-6,5.5)."<br>";
7. ?>
● sqrt
取平方根
float sqrt(float $arg)
[php] view plain copy
1. <?php
2. echo(sqrt(0))."<br>";
3. echo(sqrt(1))."<br>";
4. echo(sqrt(9))."<br>";
5. echo(sqrt(0.64))."<br>";
6. echo(sqrt(-9))."<br>";
7. ?>
● rand
产生随机数
int mt_rand(int $min, int max);
[php] view plain copy
1. <?php
2. echo rand()."<br>";
3. echo rand(10,100)."<br>";
4. ?>
● 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);
[php] view plain copy
1. <?php
2. echo time()."<br>";
3. $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs
4. echo 'Now: '. date('Y-m-d') ."<br>";
5. echo 'Next Week: '. date('Y-m-d', $nextWeek) ."<br>";
6. ?>
● date
格式化一个本地时间/日期
string date(string format[, int timestamp]);
● getdate
取得日期/时间信息
array getdate([int timestamp]);
[php] view plain copy
1. <?php
2. print_r(getdate());
3. ?>
● microtime
返回当前Unix时间戳和微秒数
mixed microtime([bool get_as_float]);
● date_default_timezone_set
设置默认时区
bool date_default_timezone_set(string timezone_identifier);
● date_default_timezone_get
获取默认时区
string date_default_timezone_get(void);
三、字符函数库
strlen
获取字符串长度
int strlen(string $str);
strtolower
字符串转换为小写
string strtolower(string $str);
strtoupper
字符串转换为大写
string strtoupper(string $str);
ucfirst
首字母大写
string ucfirst(string $str);
ucwords
将每个单词的首字母转换为大写字母
string ucwords(string $str);
ltrim
从字符串开始的位置删除空格或其他字符
string ltrim(string $str [, string $charlist]);
rtrim
从字符串结束的位置删除空格或者其他字符
string rtrim(string $str[, string $chirlist]);
trim
从字符串开始和结束的位置删除空格或者其他字符
str_replace
字符替换
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);
str_ireplace
字符替换
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);
md5
计算字符串的MD5哈希
string md5(string $str[, bool $raw_output=false]);
strpos
返回一个字符在另一个字符第一次出现的位置
int strpos(string haystack, mixed needle[, int offset]);
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言PHP频道!
喜欢 | 1
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号