Home > Backend Development > PHP Tutorial > 求大神解答一个关于foreach的有关问题

求大神解答一个关于foreach的有关问题

WBOY
Release: 2016-06-13 13:22:57
Original
826 people have browsed it

求大神解答一个关于foreach的问题
有一个XML,例如:

XML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?xml version="1.0" encoding="utf-8"?>
<top>
    <middle>
        <bottom>
            <value1>8000</value1>
            <value2>8001</value2>
            <value3>8002</value3>
        </bottom>
    </middle>
</top>

Copy after login

我想先找到middle,打印情况类似于:
bottom:
value1:8000
value2:8001
value3:8002
我用的是DOM解析代码如下:
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$mid=$xml2->getElementsByTagName("middle")->item(0);
foreach($mid->childNodes as $v1){
        echo $v1->tagName;
        foreach($v1->childNodes as $c2){
            echo $c2->tagName;
            echo $c2->nodeValue;
        }
    }

Copy after login

可以打印出来,但是会出现警告,在foreach那一行,说是参数问题,请问要怎么做呢

------解决方案--------------------
一样的道理啊

8000
8001
8002

四个换行,不是输出四队 : 吗?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template