php总结3——基本函数、流程控制中的循环

3.1 php基本函数(数学、日期、字符串)

数学函数:max mixed max(number $arg1,number $arg2,……) 求一组数据中的最大值 mixed指混合类型(类型不确定)

min mixed min(number $arg1,number $arg2,……) 求一组数据中的最小值

ceil float ceil(float $value) 向上取整

floor float floor(float $value) 向下取整

round float round(float $value) 四舍五入

rand int rand([int $min], int $max) 产生随机整数 []表示参数可有可无。

mt_rand int mt_rand([int $min], int $max) 产生更好的随机数,提高效率。

日期函数:time int time(void)返回当前的时间戳。人为规定的从1970.01.01 00:00:00 到现在的秒数。

date string date(日期格式[时间戳]) 格式化一个本地时间/日期

格式: Y 年

m 月

d 日

H 时

i 分

s 秒

strtotime int strtotime(string $time [,int $now] ) 将任何英文文本的日期时间描述解析为时间戳。

date_default_timezone_set(时区) 设置时区。中华人民共和国的时区:"Asia/Shanghai"。// 临时设置,永久设置就要改配置文件php.ini:date.timezone=PRC

字符串函数: strlen int strlen(string $string) 获取字符串长度

strtolower string strtolower(string $string) 字符串小写

strtoupper string strtoupper(string $string) 字符串全大写

ucfirst string ucfirst(string $string) 字符串中首字母大写

ucwords string ucwords(string $string) 每个单词的首字母大写

strrev string strrev(string $string) 反转字符串 hello--->olleh

trim string trim(string $string) 去掉字符串首尾的空格

str_replace mixed str_replace(mixed $search,mixed $replace, mixed $subject [, int &$count]) 替换

strpos int strpos(string $haystack, mixed $neddle[, int $offset=0]) 查找字符首次出现的位置

substr string substr(string $string, int $start[, int $length])截取字符串

md5 string mds(string $str) 字符串加密

unset void unset(mixed $var [,mixed $var [,$...]]); 释放变量

3.2 流程控制中的循环

for

for(循环条件){

循环体!

}

while

起始条件;

while(终止条件){

循环体;

步长; //注意:不写步长会陷入死循环

}

do...while

起始条件;

do{

循环体;

步长;

}while(终止条件);

注意:无论终止条件是不是成立,都会执行一次。

break continue 改变循环状态

break 终止循环

continue 结束本次循环 循环体 继续下一次循环