Array function Libraries: each

Source: Internet
Author: User
Keywords each php Chinese function manual array function library
Tags aliyun array array function library arrays example function function library html

each

(PHP3, PHP4)

Each---Returns key/http://www.aliyun.com/zixun/aggregation/9541.html from the array ">value

Syntax: array each (array array);

Description:

Returns the current Key/value pair from an array of arrays, and moves the array cursor (cursor) forward. The returned array has four elements, 0, 1, key, and value respectively. Element 0 and key are the names of the array index values, and 1 and value are the data for the element. This function returns false if the internal index of the array refers to the end of the array.

Example:

<?php

$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 '
<?php

$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 '
Each is usually used with the list, for example: $HTTP _post_vars

Example:

<?php

echo "Values submitted via POST method:<br>";

while (the list ($key, $val) = each ($HTTP _post_vars)) {

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

}

?>

After each () is executed, the array's cursor (cursor) will be on the left side of the next element of the array, and if the end of the array is reached, the cursor is at the last element.

Reference: Key () current () reset () Next () prev ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.