来自XML的PHP Echo foreach

来自XML的PHP Echo foreach,php,foreach,echo,Php,Foreach,Echo,我正在读取包含以下内容的xml文件: <imageref>image1.jpg|image2.jpg|image3.jpg|image4.jpg</imageref> <hotelname>villa test</hotelname> foreach ($filtered as $hotel) { $xmlhotels[] = array( 'image'=>(string)$hotel-

我正在读取包含以下内容的xml文件:

<imageref>image1.jpg|image2.jpg|image3.jpg|image4.jpg</imageref>
<hotelname>villa test</hotelname>


foreach ($filtered as $hotel) {     
    $xmlhotels[] = array(        
        'image'=>(string)$hotel->imageref,
        'villaname'=>(string)$hotel->hotelname
    );
}
如何仅回显xml文件中的第一个图像(image1.jpg)。

使用并执行以下操作:

foreach ($filtered as $hotel) {     
    $xmlhotels[] = array(        
        'image'=>explode('|', $hotel->imageref),
        'villaname'=>(string)$hotel->hotelname
    );
}

foreach ($myhotels as $villa) {    
    echo $villa['villaname'];
    echo $villa['image'][0];
}
foreach ($filtered as $hotel) {     
    $xmlhotels[] = array(        
        'image'=>explode('|', $hotel->imageref),
        'villaname'=>(string)$hotel->hotelname
    );
}

foreach ($myhotels as $villa) {    
    echo $villa['villaname'];
    echo $villa['image'][0];
}