当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > PHP 数组参考

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 数组参考


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1007 ::
收藏到网摘: n/a

PHP Array Introduction

The array functions allow you to manipulate arrays.
数组函数是用来对数组进行操作的。

PHP supports both simple and multi-dimensional arrays. There are also specific functions for populating arrays from database queries.
PHP支持移位或多位数组。其中包含了对数据库查询语句[database queries]进行操作的函数。


Installation
安装

The array functions are part of the PHP core. There is no installation needed to use these functions.
因为数组函数是PHP核心程序的一部分,所以无需安装。


PHP Array Functions
PHP数组函数

PHP: indicates the earliest version of PHP that supports the function.
PHP:最早支持这些函数的PHP版本
注:下面提到的字眼“键”,英文翻译是“key”;它是与值相对应的(如:Array ( [0] => a [1] => b [2] => c )中,0、1、2都是键)。

Function
函数
Description
说明
PHP
array() Creates an array
新建一个数组
3
array_change_key_case() Returns an array with all keys in lowercase or uppercase
返回字符串键名全为小写或大写的数组
4
array_chunk() Splits an array into chunks of arrays
将一个数组分割成多个
4
array_combine() Creates an array by using one array for keys and another for its values
创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值
5
array_count_values() Returns an array with the number of occurrences for each value
统计数组中所有的值出现的次数
4
array_diff() Compares array values, and returns the differences
计算数组的差集
4
array_diff_assoc() Compares array keys and values, and returns the differences
带索引检查计算数组的差集
4
array_diff_key() Compares array keys, and returns the differences
使用键名比较计算数组的差集
5
array_diff_uassoc() Compares array keys and values, with an additional user-made function check, and returns the differences
用用户提供的回调函数和值做索引检查来计算数组的差集
5
array_diff_ukey() Compares array keys, with an additional user-made function check, and returns the differences
用用户提供的回调函数做索引检查来计算数组的差集
5
array_fill() Fills an array with values
用给定的值填充数组
4
array_filter() Filters elements of an array using a user-made function
用回调函数过滤数组中的元素
4
array_flip() Exchanges all keys with their associated values in an array
交换数组中的键和值
4
array_intersect() Compares array values, and returns the matches
计算数组的交集
4
array_intersect_assoc() Compares array keys and values, and returns the matches
带索引检查计算数组的交集
4
array_intersect_key() Compares array keys, and returns the matches
使用键名比较计算数组的交集
5
array_intersect_uassoc() Compares array keys and values, with an additional user-made function check, and returns the matches
带索引检查计算数组的交集,用回调函数比较索引
5
array_intersect_ukey() Compares array keys, with an additional user-made function check, and returns the matches
用回调函数比较键名来计算数组的交集
5
array_key_exists() Checks if the specified key exists in the array
检查给定的键名或索引是否存在于数组中
4
array_keys() Returns all the keys of an array
返回数组中所有的键名
4
array_map() Sends each value of an array to a user-made function, which returns new values
将回调函数作用到给定数组的元素上
4
array_merge() Merges one or more arrays into one array
合并一个或多个数组
4
array_merge_recursive() Merges one or more arrays into one array
递归地合并一个或多个数组
4
array_multisort() Sorts multiple or multi-dimensional arrays
对多个数组或多维数组进行排序
4
array_pad() Inserts a specified number of items, with a specified value, to an array
用值将数组填补到指定长度
4
array_pop() Deletes the last element of an array
将数组最后一个元素弹出(出栈)
4
array_product() Calculates the product of the values in an array
计算数组中所有值的乘积
5
array_push() Inserts one or more elements to the end of an array
将一个或多个元素压入数组的末尾(入栈)
4
array_rand() Returns one or more random keys from an array
从数组中随机取出一个或多个元素
4
array_reduce() Returns an array as a string, using a user-defined function
用回调函数迭代地将数组简化为单一的值
4
array_reverse() Returns an array in the reverse order
返回一个元素顺序相反的数组
4
array_search() Searches an array for a given value and returns the key
在数组中搜索给定的值,如果成功则返回相应的键名
4
array_shift() Removes the first element from an array, and returns the value of the removed element
将数组开头的元素移出数组
4
array_slice() Returns selected parts of an array
从数组中取出一段
4
array_splice() Removes and replaces specified elements of an array
把数组中的一部分去掉并用其它值取代
4
array_sum() Returns the sum of the values in an array
计算数组中所有值的和
4
array_udiff() Compares array values in a user-made function and returns an array
用回调函数比较数据来计算数组的差集
5
array_udiff_assoc() Compares array keys, and compares array values in a user-made function, and returns an array
带索引检查计算数组的差集,用回调函数比较数据
5
array_udiff_uassoc() Compares array keys and array values in user-made functions, and returns an array
带索引检查计算数组的差集,用回调函数比较数据和索引
5
array_uintersect() Compares array values in a user-made function and returns an array
计算数组的交集,用回调函数比较数据
5
array_uintersect_assoc() Compares array keys, and compares array values in a user-made function, and returns an array
带索引检查计算数组的交集,用回调函数比较数据
5
array_uintersect_uassoc() Compares array keys and array vaLues in user-made functions, and returns an array
带索引检查计算数组的交集,用回调函数比较数据和索引
5
array_unique() Removes duplicate values from an array
移除数组中重复的值
4
array_unshift() Adds one or more elements to the beginning of an array
在数组开头插入一个或多个元素
4
array_values() Returns all the values of an array
返回数组中所有的值
4
array_walk() Applies a user function to every member of an array
对数组中的每个成员应用用户函数
3
array_walk_recursive() Applies a user function recursively to every member of an array
对数组中的每个成员递归地应用用户函数
5
arsort() Sorts an array in reverse order and maintain index association
对数组进行逆向排序并保持索引关系
3
asort() Sorts an array and maintain index association
对数组进行逆向排序并保持索引关系
3
compact() Create array containing variables and their values
建立一个数组,包括变量名和它们的值
4
count() Counts elements in an array, or properties in an object
计算数组中的元素数目或对象中的属性个数
3
current() Returns the current element in an array
返回数组中的当前元素
3
each() Returns the current key and value pair from an array
返回数组中当前的键和值并将数组指针向前移动一步
3
end() Sets the internal pointer of an array to its last element
将数组的内部指针指向最后一个元素
3
extract() Imports variables into the current symbol table from an array
从数组中将变量导入到当前的符号表
3
in_array() Checks if a specified value exists in an array
检查数组中是否存在某个值
4
key() Fetches a key from an array
从关联数组中取得键名
3
krsort() Sorts an array by key in reverse order
对数组按照键名逆向排序
3
ksort() Sorts an array by key
对数组按照键名排序
3
list() Assigns variables as if they were an array
给数组中的变量赋值
3
natcasesort() Sorts an array using a case insensitive "natural order" algorithm
用“自然排序”算法对数组进行不区分大小写字母的排序
4
natsort() Sorts an array using a "natural order" algorithm
用“自然排序”算法对数组排序
4
next() Advance the internal array pointer of an array
将数组中的内部指针向前移动一位
3
pos() Alias of current()
current()的别名
3
prev() Rewinds the internal array pointer
将数组的内部指针倒回一位
3
range() Creates an array containing a range of elements
建立一个包含指定范围元素的数组
3
reset() Sets the internal pointer of an array to its first element
将数组的内部指针指向第一个元素
3
rsort() Sorts an array in reverse order
对数组逆向排序
3
shuffle() Shuffles an array
将数组打乱
3
sizeof() Alias of count()
count()的别名
3
sort() Sorts an array
对数组排序
3
uasort() Sorts an array with a user-defined function and maintain index association
使用用户自定义的比较函数对数组中的值进行排序并保持索引关联
3
uksort() Sorts an array by keys using a user-defined function
使用用户自定义的比较函数对数组中的键名进行排序
3
usort() Sorts an array by values using a user-defined function
使用用户自定义的比较函数对数组中的值进行排序
3

 


PHP Array Constants
PHP数组常数

PHP: indicates the earliest version of PHP that supports the constant.
PHP:下面列举了最早支持这些函数的PHP版本:

Constant
数组常数
Description
描述
PHP
CASE_LOWER Used with array_change_key_case() to convert array keys to lower case
使用array_change_key_case()将数组关键词[array key]转化为小写字母
 
CASE_UPPER Used with array_change_key_case() to convert array keys to upper case
使用array_change_key_case()将数组关键词转化为大写字母
 
SORT_ASC Used with array_multisort() to sort in ascending order
使用array_multisort()按照升序进行分类排序
 
SORT_DESC Used with array_multisort() to sort in descending order
使用array_multisort()按照降序进行分类排序
 
SORT_REGULAR Used to compare items normally
用于与对象进行比较
 
SORT_NUMERIC Used to compare items numerically
用于与数值进行比较
 
SORT_STRING Used to compare items as strings
用于与字符串进行比较
 
SORT_LOCALE_STRING Used to compare items as strings, based on the current locale
用于与当前域中对象的字符串进行比较
4
COUNT_NORMAL    
COUNT_RECURSIVE    
EXTR_OVERWRITE    
EXTR_SKIP    
EXTR_PREFIX_SAME    
EXTR_PREFIX_ALL    
EXTR_PREFIX_INVALID    
EXTR_PREFIX_IF_EXISTS    
EXTR_IF_EXISTS    
EXTR_REFS    

评论 (0) All

登陆 | 还没注册?