0

I am reading an xml file with:

<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
    );
}

When I echo the villaname foreach value I get it.

foreach ($myhotels as $villa) {    
echo"",$villa['villaname'],""; }

How can I echo just the first image (image1.jpg) from the xml file.

0

1 Answer 1

2

Use the explode() and do something like this:

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];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.