Skip to content

Commit

Permalink
Document DOMNamedNodeMap/DOMNodeList array access syntax (php#3688)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor authored Sep 11, 2024
1 parent 3672010 commit 2352068
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions reference/dom/domnamednodemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ Remove me once you perform substitutions
</informaltable>
</section>

<section role="notes">
&reftitle.notes;
<note>
<simpara>
Nodes in the map can be accessed by array syntax.
</simpara>
</note>
</section>

<!-- {{{ See also -->
<!--
<section role="seealso">
Expand Down
32 changes: 32 additions & 0 deletions reference/dom/domnamednodemap/getnameditem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@
&null; if no node is found.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Getting an attribute on a node</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument;
$doc->load('book.xml');
$id = $doc->firstChild->attributes->getNamedItem('id');
?>
]]>
</programlisting>
</example>
<example>
<simpara>
Items can be also accessed with array syntax:
</simpara>
<programlisting role="php">
<![CDATA[
<?php
$id = $doc->firstChild->attributes['id'];
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
Expand Down
9 changes: 9 additions & 0 deletions reference/dom/domnodelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ Remove me once you perform substitutions
</para>
</section><!-- }}} -->

<section role="notes">
&reftitle.notes;
<note>
<simpara>
Nodes in the list can be accessed by array syntax.
</simpara>
</note>
</section>

<!-- {{{ See also -->
<section role="seealso">
&reftitle.seealso;
Expand Down
18 changes: 18 additions & 0 deletions reference/dom/domnodelist/item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ for ($i = 0; $i < $items->length; $i++) {
?>
]]>
</programlisting>
</example>
<example>
<simpara>
Items can be also accessed with array syntax:
</simpara>
<programlisting role="php">
<![CDATA[
<?php
for ($i = 0; $i < $items->length; $i++) {
echo $items[$i]->nodeValue . "\n";
}
?>
]]>
</programlisting>
</example>
<example>
<para>
Alternatively, you can use &foreach;, which is a much more convenient way:
</para>
Expand Down

0 comments on commit 2352068

Please sign in to comment.