Home>Article>Backend Development> php array pointer
Operation of array pointer:
Operation of moving array pointer:
Next() downward and the value of the current element will be obtained at the same time.
Prev() will get the value of the current element while going up.
End() Move to the last element unit and get the value of the last element
Reset() Move to the first unit and get the value of the first element.
If the move is unsuccessful, return false.
The parameters are all arrays that need to be operated and are passed by reference.
Get the information of the element pointed to by the pointer:
Key();//Get the subscript of the element pointed to by the current array pointer
Current() ;//Get the element pointed to by the current array pointer
Only get the data without moving the pointer
There is also a mixed operation:
You can get the information (key value) of the current pointer element and you can also move the pointer at the same time.
Each(); Get the information of the current element (key and value information),
.
Move the pointer:
We can sometimes use the characteristics of each to achieve the purpose of traversing the array:
Should be completed using a loop structure with each.
Matching conditions: When each reaches the last element, it will return false.
List function:
Limitations of List: only works for index arrays.
Use list and each to complete the traversal
But after using each traversal, the array pointer will not be reset. Requires manual reset.
Operation of array pointer:
Operation of moving array pointer:
Next() downward and the value of the current element will be obtained at the same time .
Prev() will get the value of the current element while going up.
End() Move to the last element unit and get the value of the last element
Reset() Move to the first unit and get the value of the first element.
If the move is unsuccessful, return false.
The parameters are all arrays that need to be operated and are passed by reference.
Get the information of the element pointed to by the pointer:
Key();//Get the subscript of the element pointed to by the current array pointer
Current() ;//Get the element pointed to by the current array pointer
Only get the data without moving the pointer
There is also a mixed operation:
You can get the information (key value) of the current pointer element and you can also move the pointer at the same time.
Each(); Get the information of the current element (key and value information),
.
Move the pointer:
We can sometimes use the characteristics of each to achieve the purpose of traversing the array:
should be completed using a loop structure with each.
Matching conditions: When each reaches the last element, it will return false.
List function:
Limitations of List: only works for index arrays.
Use list and each to complete the traversal
But after using each traversal, the array pointer will not be reset and needs to be reset manually.
For more articles related to PHP array pointers, please pay attention to the PHP Chinese website!