PHP gets the first element of the array and the last element

Source: Internet
Author: User

The current () function returns the value of the present element in the array.

Each array has an internal pointer to its "current" element, which initially points to the first element inserted into the array.

End ()-Points the inner pointer to the last element in the array and outputs
Next ()-Points the inner pointer to the next element in the array and outputs
Prev ()-Points the internal pointer to the previous element in the array and outputs
Reset ()-Points the inner pointer to the first element in the array and outputs
each ()-Returns the key name and key value of the current element and moves the internal pointer forward

<?PHP$tmp=Array(' A ', ' B ', ' C ', ' d ');Echo  Current($tmp)." \ n ";Echo End($tmp)." \ n ";Echo  Current($tmp)." \ n ";Reset($tmp);Echo  Current($tmp)." \ n ";?>

Output

A
D
D
A

Therefore, it is best to reset the first element of the array with current because the pointer does not necessarily point to the first element in the array.

PHP gets the first element of the array and the last element

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.