PHP: How to quickly retrieve the value of the first array element?

Source: Internet
Author: User
Using the built-in end function, you can retrieve the value of the last element: {code...}. Is there a built-in function in php that can conveniently retrieve the value of the first array element? My usual practice is to use the intermediate variable $ fruits to implement {code...} and use the built-in end function to retrieve the value of the last element:


   

Is there a built-in function in php that can conveniently retrieve the value of the first array element?
I usually use the intermediate variable $ fruits to implement


   

Reply content:

Use the built-in end function to retrieve the value of the last element:


   

Is there a built-in function in php that can conveniently retrieve the value of the first array element?
I usually use the intermediate variable $ fruits to implement


   

If the new array is used, you can use current (). If the old array is not at ease, You can reset (), current (). If you can change the data, array_shift (), the worst way is $ fruits [0] and similar methods.

We recommend that you read more manuals.

This should be the most basic Array Processing:

  • current()-The function returns the value of the array element pointed to by the internal pointer.
  • reset()-The function points the internal pointer of the array to the first element and returns the value of this element.
  • next()-The function moves the pointer to the current element to the next element and returns the value of the current element.
  • end()-The function points the internal pointer of the array to the last element and returns the value of this element.

We recommend that you setManualRead well:

Function reference-variable and type-related extensions-array

Subject: If you only need to retrieve the value of the first element of the array, we do not recommend that you usearray_shift()Because this Array Function removes the first element from the array and returns the result.

I just got the answer and found that I was rightcurrent()The definition is unclear and has been changed.

In fact, I used to followPHPWritten in:

Current.
Array_shift.

For anyone who finds this page, this answer is now applicable to 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.