电脑安全

您当前的位置:主页 > 电脑安全 >

PHP中文函数连载(二)-网络编程

来源:[db:来源]标题:   函数    编辑:电脑技术全能网 时间:2019-09-21 06:22

原标题:PHP中文函数连载(二)-网络编程
   函数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()描写:从一数组中掏出keymixed 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<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> "."<td><a href="info.php3?id=$id">$name</a></td> "."<td>$salary</td> "." </tr> ");} ?></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." "; }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动态图像的创建-网络编程

下一篇:没有了