Php is used to obtain the first array element value in an array element. php array _ PHP Tutorial

Source: Internet
Author: User
Tags array example
Php: php array. Php is used to obtain the value of the first array element in an array element. The php array example in this article describes how php can obtain the value of the first array element in an array element. We will share with you how to use php to obtain the value of the first array element in the array element. php array

This article describes how php can obtain the value of the first array element in an array element. Share it with you for your reference. The details are as follows:

In php built-in functions, the functions used to obtain array element values mainly include the reset next current prev end functions.

Reset (PHP 3, PHP 4, PHP 5)

Function syntax: mixed reset (array & array)

Purpose: This function returns the internal pointer of array to the first unit and the value of the first array unit. If the array is null, FALSE is returned. the code is as follows:

The code is as follows:

$ Array = array ('step one', 'step two', 'step three ', 'step four ');

Echo reset ($ array );

// Output: step one


Next (PHP 3, PHP 4, PHP 5)

Function syntax: mixed next (array & array)

Purpose: return the value of the next unit pointed to by the internal pointer of the array, or FALSE if no more units exist. the code is as follows:

The code is as follows:

$ Array = array ('step one', 'step two', 'WWW ', 'phpernote. com', 'step four ');

Echo next ($ array );

// Output: step two

Warning if the array contains empty cells or the unit value is 0, this function returns FALSE if it encounters these cells. to traverse arrays that may contain empty cells or whose unit value is 0 correctly, see the each () function.

Current (PHP 3, PHP 4, PHP 5)

Function syntax: mixed current (array & array)

Purpose: return the value of the array unit to which the internal pointer points. if the internal pointer points to the first unit inserted into the array, current () returns FALSE.

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

The behavior of next () and current () is similar. there is only one difference. before returning the value, move the internal pointer one byte forward. This means that it returns the value of the next array unit and moves the array pointer one bit forward. If the result of moving the pointer exceeds the end of the array unit, next () returns FALSE.

The following is an example of using related functions. the code is as follows:

The code is 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 will help you with PHP programming.

Examples in this article describes how php can obtain the value of the first array element in an array element. Share it with you...

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.