更新时间:2023-11-24 18:50:04
查看的返回值getElementsByTagName
,这将是 DOMNodeList 。
同样对于您的问题,您可以执行以下操作:
Also for your problem you could do something like:
$names = array();
foreach ($dom->getElementsByTagName("name") as $nameNode) {
$names[] = $nameNode->nodeValue;
}
您不必真正检查 getElementsByTagName ,因为它将会是一个DOMNodeList。这样你可以直接在foreach-loop中使用它来分配不需要的变量。
You don't have to actually check the return value of getElementsByTagName
, for it will allways be a DOMNodeList. This way you can use it directly in the foreach-loop whithout assigning unneeded variables.
你需要检查的是$ code> $ name的大小,循环后。
What you have to check, is the size of $names
, after the loop.