我正在阅读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
);
}
当我回应别名的foreach值时,我明白了。
foreach ($myhotels as $villa) {
echo"",$villa['villaname'],""; }
如何从xml文件中回显第一个图像(image1.jpg)。
答案 0 :(得分:2)
使用explode()并执行以下操作:
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];
}