<?php
$doc = new DomDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$iterator = new ArrayIterator(array(
array('john', 'doe', 'john.doe@example.com'),
array('jane', 'doe', 'jane.doe@example.com'),
));
$root = $doc->createElement('table');
foreach ($iterator as $row) {
$item = $doc->createElement('tr');
array_walk($row, function ($value) use (&$item, $doc) {
$content = $doc->createTextNode($value);
$cell = $doc->createElement('td');
$cell->appendChild($content);
$item->appendChild($cell);
});
$root->appendChild($item);
}
$doc->appendChild($root);
$doc->documentElement->setAttribute('class', 'foo');
echo $doc->saveHTML($doc->documentElement);
preferences:
42.89 ms | 402 KiB | 5 Q