March 27, 2012
Codeiginiter array $data view
Question by Uffo
So I need an array from my data that I can foreach
on the view, an array like this: album_name,cover_image
Here is my code:
function myFunction(){
$alb = array();
foreach($albums as $album)
{
//if($album[0]['count'] > 0){
$alb[]['album_name'] = $album['name'];
foreach($this->get_fbimages($facebook,$album['id']) as $img)
{
$alb[]['cover'] = $img[0]['picture'];
}
}
return $alb;
}
and I do array_merge($data,myFunction());
Answer by Starx
The structure of your array is invalid, to the result you want.
Try it this way.
function myFunction(){
$alb = array();
foreach($albums as $album)
{
$tempArray['album_name'] = $album['name'];
foreach($this->get_fbimages($facebook,$album['id']) as $img)
{
$tempArray['cover'][] = $img[0]['picture'];
}
$alb[] = $tempArray;
}
return $alb;
}