Skip to content
Thomas Weinert edited this page Jul 29, 2014 · 2 revisions

FluentDOM\Nodes::item()

DOMNode item(int $position);

Provides access to the node by its position in the internal list. Together with the $length property this allows to access the nodes like in a DOMNodeList.

Usage

$fd = new FluentDOM\Nodes(
  '<items><item/><item/><item/></items>'
);
$fd = $fd->find('//item');

$length = $fd->length;
for ($i = 0; $i < $length; $i++) {
  $fd->item($i)->setAttribute('index', $i);
}

echo $fd;

Output

<?xml version="1.0"?>
<items><item index="0"/><item index="1"/><item index="2"/></items>
Clone this wiki locally