php-doc-en/reference/spl/recursiveiteratoriterator/construct.xml
George Peter Banyard fda6c4efe2
Update SPL class construtor pages (#1466)
Add missing changelogs for changes in PHP 8
2022-04-07 12:40:48 +01:00

184 lines
4.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="recursiveiteratoriterator.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>RecursiveIteratorIterator::__construct</refname>
<refpurpose>Construct a RecursiveIteratorIterator</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<constructorsynopsis>
<modifier>public</modifier> <methodname>RecursiveIteratorIterator::__construct</methodname>
<methodparam><type>Traversable</type><parameter>iterator</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer>RecursiveIteratorIterator::LEAVES_ONLY</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
</constructorsynopsis>
<para>
Creates a <classname>RecursiveIteratorIterator</classname> from a <classname>RecursiveIterator</classname>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>iterator</parameter></term>
<listitem>
<para>
The iterator being constructed from. Either a
<classname>RecursiveIterator</classname> or <classname>IteratorAggregate</classname>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mode</parameter></term>
<listitem>
<para>
Optional mode. Possible values are
<simplelist>
<member>
<constant>RecursiveIteratorIterator::LEAVES_ONLY</constant>
- The default. Lists only leaves in iteration.
</member>
<member>
<constant>RecursiveIteratorIterator::SELF_FIRST</constant>
- Lists leaves and parents in iteration with parents coming first.
</member>
<member>
<constant>RecursiveIteratorIterator::CHILD_FIRST</constant>
- Lists leaves and parents in iteration with leaves coming first.
</member>
</simplelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Optional flag. Possible values are <constant>RecursiveIteratorIterator::CATCH_GET_CHILD</constant>
which will then ignore exceptions thrown in calls to <methodname>RecursiveIteratorIterator::getChildren</methodname>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="examples"><!-- {{{ -->
&reftitle.examples;
<para>
<example xml:id="recursiveiteratoriterator.example.basic"><!-- {{{ -->
<title>Iterating a RecursiveIteratorIterator</title>
<programlisting role="php">
<![CDATA[
<?php
$array = array(
array(
array(
array(
'leaf-0-0-0-0',
'leaf-0-0-0-1'
),
'leaf-0-0-0'
),
array(
array(
'leaf-0-1-0-0',
'leaf-0-1-0-1'
),
'leaf-0-1-0'
),
'leaf-0-0'
)
);
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator($array),
$mode
);
foreach ($iterator as $key => $leaf) {
echo "$key => $leaf", PHP_EOL;
}
?>
]]>
</programlisting>
<para xml:id="recursiveiteratoriterator.examples.basic.leaves-only">
Output with <literal>$mode = RecursiveIteratorIterator::LEAVES_ONLY</literal>
</para>
<screen>
<![CDATA[
0 => leaf-0-0-0-0
1 => leaf-0-0-0-1
0 => leaf-0-0-0
0 => leaf-0-1-0-0
1 => leaf-0-1-0-1
0 => leaf-0-1-0
0 => leaf-0-0
]]>
</screen>
<para xml:id="recursiveiteratoriterator.examples.basic.self-first">
Output with <literal>$mode = RecursiveIteratorIterator::SELF_FIRST</literal>
</para>
<screen>
<![CDATA[
0 => Array
0 => Array
0 => Array
0 => leaf-0-0-0-0
1 => leaf-0-0-0-1
1 => leaf-0-0-0
1 => Array
0 => Array
0 => leaf-0-1-0-0
1 => leaf-0-1-0-1
1 => leaf-0-1-0
2 => leaf-0-0
]]>
</screen>
<para xml:id="recursiveiteratoriterator.examples.basic.child-first">
Output with <literal>$mode = RecursiveIteratorIterator::CHILD_FIRST</literal>
</para>
<screen>
<![CDATA[
0 => leaf-0-0-0-0
1 => leaf-0-0-0-1
0 => Array
1 => leaf-0-0-0
0 => Array
0 => leaf-0-1-0-0
1 => leaf-0-1-0-1
0 => Array
1 => leaf-0-1-0
1 => Array
2 => leaf-0-0
0 => Array
]]>
</screen>
</example><!-- }}} -->
</para>
</refsect1><!-- }}} -->
</refentry>
<!-- 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
-->