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 setManual
Read 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 followPHP
Written in:
Current.
Array_shift.
For anyone who finds this page, this answer is now applicable to you: