$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=
| 对此文章发表了评论 |
