php array pointer

高洛峰
Release: 2023-03-05 20:30:01
Original
1674 people have browsed it


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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template