基本上我试图从几个XPath查询中提取数据,并在一个CSV提交的每一个文件拉到数据到行。我遇到的问题是循环访问特定的xPath查询并将其结果连接到一行。PHP:问题与嵌套的foreach循环
我有以下代码:
$category_titles = $xpath->query('//*[@id="shopMain"]/div/div/h1');
$category_introduction = $xpath->query('//*[@id="shopMain"]/div/div/p');
if($category_title){
foreach($category_title){
foreach($category_introduction as $node){
$test .= $node->nodeValue;
var_dump($test);
continue();
}
$test = '':
}
}
我试图环路$category_introduction
查询每个$category_title
并串连各<p>
元素。当所有的<p>
标签被连接在一起时,然后我试图跳出循环,并且只有清除了$test
才重复该过程。任何人都可以建议我可以在嵌套的foreach循环中做到这一点?我从来没有写过一个嵌套循环,并且挣扎着。