PHP Iterables
PHP में Iterable एक ऐसा data type है जिसे loop किया जा सकता है। Iterable का उपयोग
foreach के साथ किया जाता है। यह array और ऐसे objects को represent करता है जो loop
होने योग्य हों।
- Iterable में arrays और Traversable interface को implement करने वाले objects आते हैं।
- Function या method parameter को
iterabletype-hint देकर हम ensure करते हैं कि उसे केवल iterable values ही मिलें। - Iterable को
foreachलूप के साथ directly iterate किया जा सकता है।
Iterable Type Hinting
हम किसी function parameter के लिए iterable type-hint दे सकते हैं ताकि वह केवल
iterable values (array या traversable object) ही स्वीकार करे।
Banana
Mango
Iterable Return Type
हम किसी function को iterable return करने के लिए भी declare कर सकते हैं।
Orange
Iterable with Objects
अगर कोई class IteratorAggregate या Iterator interface को implement करती है,
तो उसके objects भी iterable बन जाते हैं।
Kiwi
Grapes
