Explain the usage examples of phpend () function and current () function

Source: Internet
Author: User
In php, the end () function directs the internal pointer of the array to the last element and returns the value of this element. The current () function returns the current element (unit, these two functions return the first element of the array and the last element of the array. let's take a look at the usage of these two functions. What are the functions of php end () and current () functions?

In php, the end () function directs the internal pointer of the array to the last element and returns the value of this element. The current () function returns the current element (unit, these two functions return the first element of the array and the last element of the array. let's take a look at the usage of these two functions.

End () function

The end () function points the pointer inside the array to the last element. if it succeeds, the value of this element is returned;

Example 1

Use the end () function to return the last element of the array. the code is as follows:

 

Code running result:

Current () function

The current () function returns the current element (unit) in the array ). Each array has an internal pointer pointing to its "current" element, initially pointing to the first element inserted into the array.

PS: If an empty element or element has no value, the function returns FALSE.

Example 2

Use the current () function to return the first element of the array. the code is as follows:

 

Code running result:

Example 3

Use the current () and end () functions to output the values of the current element and the last element in the array. the code is as follows:

 ";echo end($people);?>

Code running result:

[Recommended related articles]

Php array function current () definition and usage

Php operations on array functions current, next, and reset function Usage examples

The above is a detailed description of the php end () function and current () function usage instance. For more information, see other related articles in the first PHP community!

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.