PHP iterators and Kazuo Generators

Source: Internet
Author: User

PHP has a number of powerful interfaces, where arrayaccess and Iterator work together to make objects as flexible as arrays.

Of course, using arrayaccess with Iterator can be used to deal with arrays, but there is a better way to do this with the arrayiterator provided by SPL

The reason is:

Arrayiterator implement Arrayaccess, Seekableiterator, countable, searializable {}

The next step is to introduce a higher level of iterator usage.

Functions related to iterator are recorded first.

Iterator_to_array () Converts an element in an iterator to an array

Iteratoraggregate::getiterator () calls an external iterator

Arrayiterator

Iteartor_count () et cetera

PHP's use of the iterator interface is an implementation of the iterator pattern. Here, the conceptual client (implementing the iterative process), the iterator, and the specific iterator do not correspond to, foreach (), the concrete class that inherits from the iterator interface, and the array or collection that needs to be traversed.

The builder is better understood on top of the iterator.

To be continued .....

PHP iterators and Kazuo Generators

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.