PHP gets the implementation method of the first array element value in the array element, PHP array _php tutorial

Source: Internet
Author: User

PHP gets the implementation method of the first array element value in the array element, the PHP array


This article describes how PHP obtains the value of the first array element in an array element. Share to everyone for your reference. Specific as follows:

In PHP's built-in function, the function that gets the value of the array element has the following functions: Reset next Current prev end.

Reset (PHP 3, PHP 4, PHP 5)

function definition: Mixed reset (array &array)

Function: The function returns the internal pointer of the array back to the first cell and returns the value of the first array cell, FALSE if the array is empty, and the code is as follows:
Copy the code as follows: $array =array (' Step One ', ' Step ', ' step three ', ' step Four ');

echo Reset ($array);

Output: Step One
Next (PHP 3,php 4,php 5)

function definition: Mixed next (array &array)

Function: Returns the value of the next cell to which the pointer in the array is pointing, or FALSE when there are no more cells, the code is as follows:
Copy the code as follows: $array =array (' Step One ', ' step ', ' www ', ' phpernote.com ', ' step Four ');

Echo Next ($array);

Output: Step

Warning: If the array contains empty cells, or if the value of the cell is 0, the function will also return FALSE if it encounters these cells, to properly traverse an array that may contain empty cells or a cell value of 0, see each () function.

Current (PHP 3,php 4,php 5)

function definition: Mixed current (array &array)

Function: Returns the value of the array cell currently pointed to by the internal pointer, does not move the pointer, initially points to the first cell inserted into the array, and if the internal pointer points beyond the end of the cell list, current () returns FALSE.

Warning: If the array contains empty cells (0 or "", an empty string), this function also returns FALSE when it encounters this unit. This makes it impossible to use current () to determine whether the end of this array list is reached. To properly traverse an array that may contain empty cells, use the each () function.

Next () and current () behave similarly, with only a little difference, moving the inner pointer forward one bit before the return value. This means that it returns the value of the next array cell and moves the array pointer forward one bit. If the result of moving the pointer is beyond the end of the array cell, then next () returns FALSE.

The following are examples of the use of related functions, as follows:
Copy the code as follows: $transport = array (' foot ', ' www ', ' car ', ' phpernote ', ' com ');
$mode = current ($transport); $mode = ' foot ';
$mode = Next ($transport); $mode = ' www ';
$mode = Next ($transport); $mode = ' car ';
$mode = prev ($transport); $mode = ' www ';
$mode = End ($transport); $mode = ' com ';
$mode = current ($transport); $mode = ' com ';
$mode = Reset ($transport); $mode = ' foot ';

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/930490.html www.bkjia.com true http://www.bkjia.com/PHPjc/930490.html techarticle PHP Gets the implementation of the first array element value in the array element, the PHP array is an example of how PHP gets the first array element value in the array element. Share for the big ...

  • 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.