PHP-day4

11.数组

输出数组

print_r() 将数组结构进行输出

bool print_r(mixed expression[,bool return])

如果参数expression为普通的整型、字符型或实例变量,则输出该变量本身。如果为数组,则按键值和元素的顺序输出数组中的所有元素。 return为可选参数,当此参数设为TRUE时,print_r()函数将不打印结果,而是返回其输出

 

遍历数组

foreach 循环遍历数组元素

foreach(array_expression as value)

foreach(array_expression as key => value)

list()函数 把数组中的值赋给变量

array list(mixed ...)

 

统计数组元素个数

int count(mixed array[,int mode])

array  必要参数,输入的数组

mode  可选参数,其值为0或COUNT_RECURSIVE(1)。count() 将递归地对数组计数。对计算多维数组的所有单元尤其有用。mode 的默认值是 0。count() 识别不了无限递归。

 

查询数组中指定元素

mixed array_search(mixed needle,array haystack[,bool strict])

needle    指定在数组中搜索的值

haystack  指定被搜索的数组

strict    可选参数,如果为true,还将在数组中检查给定值的类型

 

获取数组中最后一个元素

mixed array_pop(array array)

获取并返回数组的最后一个元素,并将数组的长度减1,如果数组为空或不是数组则返回null

 

向数组中添加元素

int array_push(array array,mixed var[,mixed...])

array为指定的数组,var为添加到数组中的值

 

删除数组中重复元素

array array_unique(array array)

 

12.时间和日期

获取本地化时间戳

mktime() 取得一个日期的 Unix 时间戳

int mktime([int hour[,int minute[,int second[,int month[,int day[,int year[,int is_dst]]]]]]])

hour 小时  minute 分钟  second 秒  month 月  day 日  year 年  is_dst 是否夏时令(1是,0不是,-1默认值)

 

获取当前时间戳

time() 返回当前的 Unix 时间戳

int time(void)

 

获取当前日期和时间

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

string date(string format[,int timestamp])

 

获取日期信息

getdate() 获取日期指定部分的相关信息

array getdate(int timestamp)

 

检验日期有效性

checkdate()

bool checkdate(int month,int day,int year)

 

显示本地化的日期和时间

setlocale() 设置本地化环境和格式化输出日期和时间

string setlocale(string category[,string locale])

strftime() 根据本地化设置来格式化输出日期和时间

string strftime(string format,int timestamp)

 

将日期和时间解析为UNIX时间戳

strtotime() 可以将任何英文文本的日期和时间解析为UNIX时间戳

int strtotime(string time[,int now])

posted @ 2016-09-30 10:38  大大大尾巴羊  阅读(97)  评论(0)    收藏  举报