Reputation: 349
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
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
Reputation:
You can use:
1- array
$image[] = JURI::base() . $imagesnonnull;
2- or String
$image.= JURI::base() . $imagesnonnull;
Upvotes: 0
Reputation: 32155
how can I then have two variables containing the url data.
By pushing them onto an array
$urls[] = $url;
Upvotes: 1