1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 07:02:15 +01:00
Files
archived-doc-zh/language/types/iterable.xml
2025-04-24 10:09:43 +08:00

67 lines
1.7 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: daijie Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<sect1 xml:id="language.types.iterable">
<title>Iterable 可迭代对象</title>
<para>
<type>Iterable</type> 是内置编译时 <literal>array|Traversable</literal>
<!-- Need to improve rendering of free-standing type elements in PhD
<type class="union"><type>array</type><type>Traversable</type></type>.
-->
的类型别名。从 PHP 7.1.0 到 PHP 8.2.0 之间的描述来看,<type>iterable</type>
是内置伪类型充当上述类型别名也可以用于类型声明。iterable 类型可用于 &foreach;
或在<link linkend="language.generators">生成器</link>中使用 <command>yield from</command>
</para>
<note>
<para>
将可迭代对象声明为返回类型的函数也可能是 <link
linkend="language.generators">生成器</link>
<example>
<title>
可迭代生成器返回类型的示例
</title>
<programlisting role="php">
<![CDATA[
<?php
function gen(): iterable {
yield 1;
yield 2;
yield 3;
}
foreach(gen() as $value) {
echo $value, "\n";
}
?>
]]>
</programlisting>
</example>
</para>
</note>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->