I have a small issue i can't seem to work around. i have some data i'm pulling from the database and before i display the data, i want to manipulate some values in there. here's my function handling these:
public function getPageContent($id)
{
$menutopic_model = new Menu_Topic();
$content = $menutopic_model->getAllContent($id);
//var_dump($content);
$data = array();
foreach ($content as $value)
{
$title = explode(',', $value->title);
$filename = explode(',', $value->filename);
$data['topicname'] = $value->topicname;
$data['title'] = $title;
$data['filename'] = $filename;
}
//var_dump($data);
}
Now, when i dump var_dump($content);, i get the entire array of data as it should be:
array(2) {
[0]=>
object(stdClass)#346 (3) {
["topicname"]=>
string(19) "Signs giving orders"
["title"]=>
string(42) "Stop,No entry,No cycling,No motor vehicles"
["filename"]=>
string(179) "DQP0GVcUA2dG8ZfqeVYLO68YodgYnJMOjJw2o2iC.png,vWUcHGX3VVKPT08JXh9mAqZ40pT0vfDJ78Yoqovz.png,bplX8bbwHzHKX9n6SvvQiYNhkWwKxi2bhsrQ94U2.png,8KAEovxQn3EgzHoZg1euSgNYTFupnLdKusJ4SIEP.png"
}
[1]=>
object(stdClass)#345 (3) {
["topicname"]=>
string(13) "Warning Signs"
["title"]=>
string(111) "Road narrows ahead both sides,Road narrows on right (left if symbol reversed),Crossroads,Junction on bend ahead"
["filename"]=>
string(179) "uZ7fnDjlYfKU3pdSQ7wAq4siFryA6jSEitmRyPhp.png,4pslo6cC0I2E606DscWxiDD3sCBW7ZGaESQES4r0.png,xdVBMpV6PTLtX48M67kfWOqy59rsYMDZMuWbqDwl.png,hLtIGikARgARqmSqit4mqNXRFJthipH6O5vqxlbN.png"
}
}
but after passing the data through the foreach, this var_dump($data); only returns the last item in the array:
array(3) {
["topicname"]=>
string(13) "Warning Signs"
["title"]=>
array(4) {
[0]=>
string(29) "Road narrows ahead both sides"
[1]=>
string(47) "Road narrows on right (left if symbol reversed)"
[2]=>
string(10) "Crossroads"
[3]=>
string(22) "Junction on bend ahead"
}
["filename"]=>
array(4) {
[0]=>
string(44) "uZ7fnDjlYfKU3pdSQ7wAq4siFryA6jSEitmRyPhp.png"
[1]=>
string(44) "4pslo6cC0I2E606DscWxiDD3sCBW7ZGaESQES4r0.png"
[2]=>
string(44) "xdVBMpV6PTLtX48M67kfWOqy59rsYMDZMuWbqDwl.png"
[3]=>
string(44) "hLtIGikARgARqmSqit4mqNXRFJthipH6O5vqxlbN.png"
}
}
what should i change in the above to get the correct result?
$data['topicname'] = $value->topicname;- which will always gonna be the last item.