1 回答

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊
看起來(lái)你需要在你的結(jié)構(gòu)中更深入地循環(huán),因?yàn)槟阌幸粋€(gè)數(shù)組的數(shù)組。
解決方案 1:更深層次的循環(huán)
<?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 關(guān)注
- 114 瀏覽
添加回答
舉報(bào)