1

嘿那里。我有一个有 7 个房间的单元,但其中只有 5 个有照片。我的目标是将它们中的每一个显示在正确的位置,即 1#room->1img, 2#room->1img, 3#room->3img, 4#room->2img, 5#room->1img, 6 #room->0img, 7#room->0img。这是我的数组:

Array
(
    [0] => Array
        (
            [large] =>room_galleries/4/large/XWKgkS_a503fd0054f4c6a04e72d95cef5d8b6a.jpg
            [thumb] =>room_galleries/4/thumb/XWKgkS_a503fd0054f4c6a04e72d95cef5d8b6a.jpg
        )

)
Array
(
    [0] => Array
        (
            [large] => room_galleries/13/large/96Hk2r_6e2507fabb7313d18d9a694eda740337.jpg
            [thumb] => room_galleries/13/thumb/96Hk2r_6e2507fabb7313d18d9a694eda740337.jpg
        )

)
Array
(
    [0] => Array
        (
            [large] => room_galleries/38/large/HXJTWL_98e71e7fbc9bab7096f0387b2ffa9ab9.jpg
            [thumb] => room_galleries/38/thumb/HXJTWL_98e71e7fbc9bab7096f0387b2ffa9ab9.jpg
        )

    [1] => Array
        (
            [large] =>room_galleries/38/large/XCquAP_5ccd9c6af4501a1c81b1e6b532100036.jpg
            [thumb] =>room_galleries/38/thumb/XCquAP_5ccd9c6af4501a1c81b1e6b532100036.jpg
        )

    [2] => Array
        (
            [large] => room_galleries/38/large/iDe0SN_6dcf2e3c9dc2180cbed5c98f0adbb0e9.jpg
            [thumb] => room_galleries/38/thumb/iDe0SN_6dcf2e3c9dc2180cbed5c98f0adbb0e9.jpg
        )

)
Array
(
    [0] => Array
        (
            [large] => room_galleries/39/large/FDM6JV_63243ea8328f4ba74200ea3c2d32aa0c.jpg
            [thumb] => room_galleries/39/thumb/FDM6JV_63243ea8328f4ba74200ea3c2d32aa0c.jpg
        )

    [1] => Array
        (
            [large] => room_galleries/39/large/ccNOdB_a12501222468f3e38f05433c002b8851.jpg
            [thumb] => room_galleries/39/thumb/ccNOdB_a12501222468f3e38f05433c002b8851.jpg
        )

)
Array
(
    [0] => Array
        (
            [large] => room_galleries/41/large/IosSy8_e4d6ff02cc21212c6cf6e616619f11b6.jpg
            [thumb] => room_galleries/41/thumb/IosSy8_e4d6ff02cc21212c6cf6e616619f11b6.jpg
        )

)

这是我的php代码:

if( !empty( $r['images'])){
            $images = unserialize( $r['images'] );
            foreach( $images as $img ){
                $galleries[$r['roomID']][] = array(
                    'large' => ROOM_GALLERY_HTTP . $r['roomID'] . '/large/' . $img,
                    'thumb' =>  ROOM_GALLERY_HTTP . $r['roomID'] . '/thumb/' . $img,
                );  
            }
            print_r( $galleries[$r['roomID']] ); // the array above
            $tpl->set( 'galleries', $galleries[$r['roomID']] ); // set a tag named galleries for my template
        }

我的问题是它显示循环中的最后一个元素 7 次:

Array
(
    [0] => Array
        (
            [large] => room_galleries/41/large/IosSy8_e4d6ff02cc21212c6cf6e616619f11b6.jpg
            [thumb] => room_galleries/41/thumb/IosSy8_e4d6ff02cc21212c6cf6e616619f11b6.jpg
        )

)

有什么建议么?

4

0 回答 0