CoalaWeb
CoalaWeb

Reputation: 349

Best way to separate two strings from a variable

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.

Upvotes: 0

Views: 111

Answers (3)

ram obrero
ram obrero

Reputation: 197

 $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

Upvotes: 0

user1646111
user1646111

Reputation:

You can use:

1- array

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

2- or String

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

Upvotes: 0

Mike B
Mike B

Reputation: 32155

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

By pushing them onto an array

$urls[] = $url;

Upvotes: 1

Related Questions