分享
 
 
 

PHP中文函数连载(二)

王朝php·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

函数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.

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:<br>";

while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {

echo "$key => $val<br>";

}

函数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]."\n"; }

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

函数list()

描述:

用类似数组的方式去指定一整串变量的值

Example 1. list() example

<table> <tr> <th> Employee name</th>

<th>Salary</th> </tr>

<?php $result = mysql($conn, "SELECT id, name, salary FROM employees");

while (list($id, $name, $salary) = mysql_fetch_row($result)) {

print(" <tr>\n"."<td><a href=\"info.php3?id=$id\">$name</a></td>\n"."<td>$salary</td>\n"." </tr>\n");

}

?>

</table>

函数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."\n";

}

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]."\n";

}

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() example

function mycompare($a, $b) {

if ($a == $b) return 0;

return ($a > $b) ? -1 : 1;

}

$a = array(4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");

uksort($a, mycompare);

while(list($key, $value) = each($a)) {

echo "$key: $value\n";

}

This example would display: 20: twenty 10: ten 4: four 3: three

函数usort()

描述:

以自定义的方式以value排列

void usort (array array, function cmp_function);

This function will sort an array by its values 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. usort() example

function cmp($a,$b) {

if ($a == $b) return 0;

return ($a > $b) ? -1 : 1;

}

$a = array(3,2,5,6,1);

usort($a, cmp);

while(list($key,$value) = each($a)) {

echo "$key: $value\n";

}

This example would display: 0: 6 1: 5 2: 3 3: 2 4: 1 Obviously in this trivial case the rsort() function would be more appropriate.

BC (Arbitrary Precision) Functions

函数bcadd()

描述:

Add two arbitrary precision numbers

string bcadd (string left operand, string right operand, int [ scale ]); 左面的字符加右面的字符,返回一个字符。

函数bccomp()

描述:

int bccomp (string left operand, string right operand, int [ scale ]);

左面的字符和右面的字符进行比较,如果相等的话返回0,如果左面的比右面的长返回+1,右面的比左面的长返回-1

函数bcdiv()

描述:

Divide two arbitrary precision numbers

string bcdiv (string left operand, string right operand, int [ scale ]); 将左面的字符串以右面的字符串为标准分开

函数bcmod()

描述:

Get modulus of an arbitrary precision number

string bcmod (string left operand, string modulus);

用右面的modulus操作左面的字符串

函数bcmul()

描述:

Multiply two arbitrary precision number

string bcmul (string left operand, string right operand, int [ scale ]);

Multiply the left operand by the right operand and returns the result. The optional scale sets the number of digits

after the decimal place in the result.

函数bcpow()

描述:

Raise an arbitrary precision number to another.

Raise x to the power y . The scale can be used to set the number of digits after the decimal place in the result.

函数bcscale()

描述:

Set default scale parameter for all bc math functions.

string bcscale (int scale);

This function sets the default scale parameter for all subsequent bc math functions that do not explicitly specify a scale

parameter

函数bcsqrt()

描述;

string bcsqrt (string operand, int scale);

返回字符的平方根

函数bcsub()

描述:

string bcsub (string left operand, string right operand, int [ scale ]);

将右面的字符减

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有