0

I have managed to retrieve the data I'm looking for which is in the form of two urls and I need to extract them into two separate variables. Am I retrieving the data the most efficient way and how can I then have two variables containing the url data.

$item = $this->_item;//Item ID

foreach ($item->getElements() as $elements) {
    $images = $elements->get('file');

    if(!empty($images)) {
        $imagesnonnull = $images;
        $image = JURI::base() . $imagesnonnull;
        var_dump($image);
    }
}

The var_dump result is below:

string(33) "http://demo.com/images/image1.jpg"
string(33) "http://demo.com/images/image2.jpg" 

I happy to provide more info and try any suggestions to improve the code.

3 Answers 3

1

how can I then have two variables containing the url data.

By pushing them onto an array

$urls[] = $url;
1
  • Thanks for you quick response and a very easy answer too
    – CoalaWeb
    Apr 1, 2013 at 17:51
0

You can use:

1- array

$image[] = JURI::base() . $imagesnonnull;

2- or String

$image.= JURI::base() . $imagesnonnull;
1
  • Thanks for you quick response and for giving me a couple of options. Looking at it now it was a simple solution thanks to both yourself and Mike for not making me feel silly for asking it.
    – CoalaWeb
    Apr 1, 2013 at 17:54
0
 $item = $this->_item;//Item ID
 $urls = array();

            foreach ($item->getElements() as $elements) {
                $images = $elements->get('file');

                   if(!empty($images)) {
                       $imagesnonnull = $images;
                       $image = JURI::base() . $imagesnonnull;
                       //var_dump($image);
                       $urls[] = $image;
                   }
            }

get array values afterwards

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.