Getting the current array key and value in the php array Getting Started Tutorial

Source: Internet
Author: User
Getting the current array key and value in the php array Getting Started Tutorial
This article describes how to obtain the keys and values of the current array in the php array. For more information, see.

In the php array function, the each () function returns the current key/value pair of input_array and pushes the pointer to a position.

Format: array each (array)

The returned array contains four keys. Keys 0 and key contain the key name, while Keys 1 and value contain the corresponding data. If the pointer before execution of each () is located at the end of the array, false is returned.

For example:

      apple [value] => apple [0] => 0 [key] => 0 )  ?>

Each () is often used in combination with list () to traverse arrays.

For example, the entire array is output cyclically:

      $val
"; } //by bbs.it-home.org // 0 => apple // 1 => banana // 2 => orange // 3 => pear ?>

Since the original array pointer is reset when an array is assigned to another array, if $ fruits is assigned to another variable in the previous example, an infinite loop will occur. This completes the array traversal.

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.