1 回答
TA贡献1775条经验 获得超11个赞
看起来你需要在你的结构中更深入地循环,因为你有一个数组的数组。
解决方案 1:更深层次的循环
<?php
$reference = $_POST['varname'];
$xml = simplexml_load_file('save.xml') or die("can not find file");
$result = $xml->xpath("//property[property_reference='$reference']");
foreach ($result as $elements) {
foreach ($elements as $pictures) {
foreach ($pictures as $picture) { ?>
<img class="card-img-top" height='240px' width='340px' src="<?php echo $picture->filename?> " alt="Card image cap">
<?php }
}
}
解决方案 2:使用更深层次的 XPath:
<?php
$reference = $_POST['varname'];
$xml = simplexml_load_file('save.xml') or die("can not find file");
$pictures = $xml->xpath("//property[property_reference='$reference']/pictures");
foreach ($pictures as $picture) { ?>
<img class="card-img-top" height='240px' width='340px' src="<?php echo $picture->filename?> " alt="Card image cap">
<?php }
- 1 回答
- 0 关注
- 86 浏览
添加回答
举报