只是想知道为什么下面的代码不会遍历
DOMDocument::getElementsByTagName
<?php
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML('<html><head>...blablabla...</html>');
$elements = $dom->getElementsByTagName('div');
array_walk($elements, 'var_dump'); // doesn't work ?>
但以下代码确实有效:
<?php
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML('<html><head>...blablabla...</html>');
$elements = $dom->getElementsByTagName('div');
foreach($elements as $element) {
var_dump($element); // does work
} ?>