- iterator_to_array: documentation ( source)
<?php
$xml = new SimpleXMLElement('<foo bar="baz"></foo>');
function iterator(SimpleXMLElement $xml): iterable {
foreach ($xml->children() as $img) {
yield $img["src"] ?? "";
}
}
iterator_to_array(iterator($xml->bar));