Not sure on this one and was hoping you would be able to help me out on this one ...
Here's my code
Loader::library('file/types');
$ih = Loader::helper('image');
$names = explode("||",$this->tName);
$urls = explode("||",$this->tUrl);
$fIDs = explode("||",$this->fID);
Loader::model('file');
$i = Loader::helper('image');
$v = array();
$cc = 0;
foreach ($names as $k=>$n){
if (intval($fIDs[$k]) > 0 ) :
$img = $test = File::getByID($fIDs[$k]);
$fv = $img->getExtension();
$ft = FileTypeList::getType($fv);
$img = $ft->type == 1 ? $img : false;
else :
$img = false;
endif;
$v[$cc]['name'] = $n;
$v[$cc]['url'] = $urls;
$v[$cc]['src'] = $img ? $ih->getThumbnail($img,100,100)->src : false;
$cc ++;
}
return $v;
And what i'm having issues with is getting the array values from $urls within this code. (5th last one)
foreach ($names as $k=>$n){
if (intval($fIDs[$k]) > 0 ) :
$img = $test = File::getByID($fIDs[$k]);
$fv = $img->getExtension();
$ft = FileTypeList::getType($fv);
$img = $ft->type == 1 ? $img : false;
else :
$img = false;
endif;
$v[$cc]['name'] = $n;
$v[$cc]['url'] = $urls;
$v[$cc]['src'] = $img ? $ih->getThumbnail($img,100,100)->src : false;
$cc ++;
}
return $v;
Thanks for all your help. Appreciate it.
I think you have to do something like this:
$i = 0;
foreach ($names as $k=>$n){
if (intval($fIDs[$k]) > 0 ) :
$img = $test = File::getByID($fIDs[$k]);
$fv = $img->getExtension();
$ft = FileTypeList::getType($fv);
$img = $ft->type == 1 ? $img : false;
else :
$img = false;
endif;
$v[$cc]['name'] = $n;
$v[$cc]['url'] = $urls[$i]; //changed
$v[$cc]['src'] = $img ? $ih->getThumbnail($img,100,100)->src : false;
$cc ++;
$i++; //changed
}
return $v;
Since you are looping through the names array using $k as the index, you can access the matching url with the same index. So you could change the line to:
$v[$k]['url'] = $urls[$k];
There's no need to keep track of the index using the $cc variable since $k already represents the current index in the names array. You are already accessing the fIDs array the same way (using $k).