0

我想为每个唯一 ID 显示来自 XML 请求的图像。应该显示总共三张图像,但我得到了三次相同的图像。

ID 在此处正确存储:

    $simIds = array(
    "id1" => $similarObject->place[0]['place_id'],
    "id2" => $similarObject->place[1]['place_id'],
    "id3" => $similarObject->place[2]['place_id'],
);

这是我的 foreach 循环:

foreach ($simIds as $foo) {
    $simPhotoFile = $photoUrl.$foo;
    $simPhotoObject = simplexml_load_file($simPhotoFile);
    $simPhotoSrc = array (
        'src1' => $simPhotoObject->photos->photo_set->square,
        'src2' => $simPhotoObject->photos->photo_set->square,
        'src3' => $simPhotoObject->photos->photo_set->square,       
    );  
}

相关的 HTML:

<p><img src="<?= $simPhotoSrc['src1'] ?>" alt="Image load failed" /><img src="<?= $simPhotoSrc['src2'] ?>" alt="Image load failed" /><img src="<?= $simPhotoSrc['src3'] ?>" alt="Image load failed" /></p>

我现在不确定我做错了什么,或者是否有更好的方法来解决这个问题。谢谢你的帮助!

4

1 回答 1

0
$simPhotoSrc = array();
foreach ($simIds as $foo) {
    $simPhotoFile = $photoUrl.$foo;
    $simPhotoObject = simplexml_load_file($simPhotoFile);
    $simPhotoSrc[] = $simPhotoObject->photos->photo_set->square
}

html:

<p><img src="<?= $simPhotoSrc[0] ?>"/><img src="<?= $simPhotoSrc[1] ?>" /><img src="<?= $simPhotoSrc[2] ?>" /></p>
于 2012-04-21T22:58:25.717 回答