Hướng dẫn php multipleiterator - nhiều trình lặp php
Show
= new ArrayIterator(array(1,2,3)); (Php 5, Php 7, Php 8) Nội phân Chính showShow (Php 5, Php 7, Php 8)Nội phân Chính show Nội phân Chính showGiới thiệuBản tóm tắt giao diện Xác định trướcMục lục Giao diện cho các trình lặp bên ngoài hoặc các đối tượng có thể tự lặp lại trong nội bộ.
__construct() { PHP đã cung cấp một số trình lặp trong nhiều nhiệm vụ hàng ngày. Xem SPL Iterators cho một danh sách. string(18) "myIterator::rewind" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(0) string(12) "firstelement" string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(1) string(13) "secondelement" string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(2) string(11) "lastelement" string(16) "myIterator::next" string(17) "myIterator::valid" Bản tóm tắt giao diện
Ví dụ số 1 sử dụng cơ bản ¶ Ví dụ này chứng minh trong đó các phương thức đặt hàng được gọi khi sử dụng foreach với một trình lặp.
Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:
This iterator has a misleading name and description - it actually acts as a parallel iterator: You attach one or more iterators with a key, integer or NULL, and when you iterate over the MultipleIterator, as the result for current() you get ALL results from all attached iterators as an array (under the key or integer you attached it with), and the same is true for the key() call. 5Iterator :: hiện tại - trả về phần tử hiện tại ¶ Iterator :: phím - Trả lại khóa của phần tử hiện tại
This iterator has a misleading name and description - it actually acts as a parallel iterator: You attach one or more iterators with a key, integer or NULL, and when you iterate over the MultipleIterator, as the result for current() you get ALL results from all attached iterators as an array (under the key or integer you attached it with), and the same is true for the key() call. 8Iterator :: Tiếp theo - Chuyển tiếp đến phần tử tiếp theo ¶ Iterator :: tua lại - tua lại trình lặp lại phần tử đầu tiên
valid() will be valid if any or all iterators are valid, depending on the setting of the $flags - with ANY, you can iterate over a set of iterators with some of them ending before others, and get NULL results from these iterators until the last iterator is at it's end. With ALL, iteration stops when the first iterator stops delivering results. 2Iterator :: hợp lệ - kiểm tra xem vị trí hiện tại có hợp lệ không ¶ Iterator :: phím - Trả lại khóa của phần tử hiện tại
Iterator :: Tiếp theo - Chuyển tiếp đến phần tử tiếp theo valid() will be valid if any or all iterators are valid, depending on the setting of the $flags - with ANY, you can iterate over a set of iterators with some of them ending before others, and get NULL results from these iterators until the last iterator is at it's end. With ALL, iteration stops when the first iterator stops delivering results. 2Iterator :: tua lại - tua lại trình lặp lại phần tử đầu tiên ¶ Iterator :: phím - Trả lại khóa của phần tử hiện tại
next() and rewind() will be called on all attached iterators in every case. 2Iterator :: Tiếp theo - Chuyển tiếp đến phần tử tiếp theo ¶ Iterator :: tua lại - tua lại trình lặp lại phần tử đầu tiên
valid() will be valid if any or all iterators are valid, depending on the setting of the $flags - with ANY, you can iterate over a set of iterators with some of them ending before others, and get NULL results from these iterators until the last iterator is at it's end. With ALL, iteration stops when the first iterator stops delivering results. 2Iterator :: hợp lệ - kiểm tra xem vị trí hiện tại có hợp lệ không ¶ Robert_e_lee tại Dell Dot Com ¶
12 năm trước ¶
13 năm trước ¶ Iterator :: phím - Trả lại khóa của phần tử hiện tại
6Iterator :: Tiếp theo - Chuyển tiếp đến phần tử tiếp theo ¶ Iterator :: tua lại - tua lại trình lặp lại phần tử đầu tiên
valid() will be valid if any or all iterators are valid, depending on the setting of the $flags - with ANY, you can iterate over a set of iterators with some of them ending before others, and get NULL results from these iterators until the last iterator is at it's end. With ALL, iteration stops when the first iterator stops delivering results. 2Iterator :: hợp lệ - kiểm tra xem vị trí hiện tại có hợp lệ không ¶ Robert_e_lee tại Dell Dot Com ¶
valid() will be valid if any or all iterators are valid, depending on the setting of the $flags - with ANY, you can iterate over a set of iterators with some of them ending before others, and get NULL results from these iterators until the last iterator is at it's end. With ALL, iteration stops when the first iterator stops delivering results. 212 năm trước ¶
Rocketinabog tại Techno-Monks Dot Net
foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. valid() will be valid if any or all iterators are valid, depending on the setting of the $flags - with ANY, you can iterate over a set of iterators with some of them ending before others, and get NULL results from these iterators until the last iterator is at it's end. With ALL, iteration stops when the first iterator stops delivering results. 213 năm trước ¶ Robert_e_lee tại Dell Dot Com ¶ foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. 12 năm trước ¶ Iterator :: tua lại - tua lại trình lặp lại phần tử đầu tiên foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. 7Iterator :: hợp lệ - kiểm tra xem vị trí hiện tại có hợp lệ không ¶
foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment. foreach ( Key Note that PHP 5.4 and 5.3 do not support accessing the key() values in foreach loops because they expect them to not be an array - doing so will cause "Warning: Illegal type returned from MultipleIterator::key()" and the result of (int)0 as the key for all iterations. Without the MultipleIterator::MIT_KEYS_ASSOC flag, the MultipleIterator will create numeric indices based on the order of attachment.
class myIterator implements Iterator { 0Rocketinabog tại Techno-Monks Dot Net ¶
class myIterator implements Iterator { 6Rocketinabog tại Techno-Monks Dot Net ¶ 13 năm trước
Shaun tại slickdesign dot com dot au ¶ ¶ 3 năm trước
public function 2Chức năng lặp đi lặp lại nào sau đây?Các loại lặp:.. Đầu vào lặp lại .. Đầu ra lặp .. Người chuyển tiếp Iterator .. Trình lặp hai chiều .. Trình lặp lại truy cập ngẫu nhiên .. Là một đối tượng có thể lặp lại PHP?PHP cho phép bạn tạo các đối tượng có thể lặp lại. Chúng có thể được sử dụng trong các vòng lặp thay vì mảng vô hướng. Ererables thường được sử dụng làm bộ sưu tập đối tượng.. These can be used within loops instead of scalar arrays. Iterables are commonly used as object collections. Loại trả lại là gì?Có thể sử dụng cũng có thể được sử dụng như một loại trả về để chỉ ra một hàm sẽ trả về một giá trị có thể lặp lại. Nếu giá trị trả về không phải là một mảng hoặc thể hiện có thể vượt qua, một kiểu người sẽ bị ném. Ví dụ #3 Ví dụ về loại trả về. function Bar (): itable {to indicate a function will return an iterable value. If the returned value is not an array or instance of Traversable, a TypeError will be thrown. Example #3 Iterable return type example. function bar(): iterable { Trình lặp PHP quan trọng như thế nào trong một ứng dụng?Trình lặp khuyến khích bạn xử lý dữ liệu lặp đi lặp lại, thay vì đệm nó trong bộ nhớ. Mặc dù có thể làm điều này mà không cần tererators, nhưng sự trừu tượng mà họ cung cấp che giấu việc thực hiện giúp chúng thực sự dễ sử dụng.encourage you to process data iteratively, instead of buffering it in memory. While it is possible to do this without iterators, the abstractions they provide hide the implementation which makes them really easy to use. |