首页 > php教程 > PHP源码 > 正文

PHP中文函数连载(二)

php中文网
发布: 2016-06-08 17:32:45
原创
1129人浏览过
<script>ec(2);</script>

函数count()
描述:
计算一变量中元素的个数
int count (mixed var);
Returns the number of elements in var , which is typically an array (since anything else will have one element).
Returns 0 if the variable is not set.
Returns 1 if the variable is not an array.

 

函数current()
描述:
传回数组指针目前所指的元素

 

mixed current (array array);

 

Each array variable has an internal pointer that points to one of its elements. In addition, all of the elements in the array are linked by a bidirectional linked list for traversing purposes. The internal pointer points to the first element that was inserted to the array until you run one of the functions that modify that pointer on that array.

立即学习PHP免费学习笔记(深入)”;

 

The current() function simply returns the array element that's currently being pointed by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list, current() returns false.

 

函数each()
描述:
返回数组中下一对key/value的值

 

array each (array array);

 

Returns the current key/value pair from the array array and advances the array cursor. This pair is returned in a four-element array, with the keys 0 , 1 , key , and value . Elements 0 and key each contain the key name of the array element, and 1 and value contain the data.

 

Example 1. each() examples

 

$foo = array( "bob", "fred", "jussi", "jouni" ); $bar = each( $foo );
$bar now contains the following key/value pairs:

 

0 => 0
1 => 'bob'
key => 0
value => 'bob'

 

$foo = array( "Robert" => "Bob", "Seppo" => "Sepi" ); $bar = each( $foo );

 

$bar now contains the following key/value pairs:

 

0 => 'Robert'
1 => 'Bob'
key => 'Robert'
value => 'Bob'

 

Example 2. Traversing $HTTP_POST_VARS with each()

 

echo "Values submitted via POST method:
";
while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
echo "$key => $val
";
}

 

函数end()
描述:
将数组中的指针移到最后一个
end (array array);
end() advances array 's internal pointer to the last element.

 

函数key()
描述:
从一数组中取出key
mixed key (array array);
key() returns the index element of the current array position.

 

函数ksort()
描述:
以key来排列一数组
Example 1. ksort() example

 

$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
ksort($fruits);
for(reset($fruits);
$key = key($fruits);
next($fruits)) { echo "fruits[$key] = ".$fruits[$key]." "; }

 

This example would display: fruits[a] = orange fruits[b] = banana fruits[c] = apple fruits[d] = lemon

 

函数list()
描述:
用类似数组的方式去指定一整串变量的值
Example 1. list() example

 



while (list($id, $name, $salary) = mysql_fetch_row($result)) {
print(" "." "." "." ");
}
?>
Employee name Salary
$name$salary

 

函数next()
描述:
将数组的指向指到下一组数据

 


函数pos()
描述:
传回数组的当前的数据

 

函数prev()
描述:
传回数组的前一条的数据

 

函数reset()
描述:
数组的指针指到第一条

 

函数rsort ()
描述:
以倒序方式排列一个数组
Example 1. rsort() example

 

$fruits = array("lemon","orange","banana","apple");
rsort($fruits);
for(reset($fruits); ($key,$value) = each($fruits); ) {
echo "fruits[$key] = ".$value." ";
}

 

This example would display: fruits[0] = orange fruits[1] = lemon fruits[2] = banana fruits[3] = apple The fruits have been sorted in reverse alphabetical order.

 

函数sizeof()
描述:
取得一个数组的大小和元素的数目

 

函数sort()
描述:
排序数组
Example 1. sort() example

 

$fruits = array("lemon","orange","banana","apple");
sort($fruits);
for(reset($fruits);
$key = key($fruits);
next($fruits)) {
echo "fruits[$key] = ".$fruits[$key]." ";
}

 

This example would display: fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange The fruits have been sorted in alphabetical order.

 

函数uasort()
描述:
以自定义的方式排列一个数组且序列不变。

 


函数uksort()
描述:
以自定义的方式以key排列
This function will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. Example 1. uksort()

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号