У меня есть функция модели codeigniter, которая должна возвращать такой массив ...
{"speakers":[{
"id":"1",
"name":"Jack",
"events":{
"id":"1"
"name":"event1",
},
{
"id":"2"
"name":"event2",
},
"status":"Active",
},
{
"id":"2",
"name":"Tom",
"events":{
"id":"3"
"name":"event3",
},
"status":"Active",
},
{
"id":"3",
"name":"Maria",
"events":{
"id":"1"
"name":"event1",
},
"status":"Active",
}]
}
Это мой код:
function speakers()
{
$speakers=$this->db->get("speakers_tbl");
$data = array();
if($speakers->num_rows()>0)
{
foreach ($speakers->result_array() as $row)
{
$this->db->from('events_tbl');
$this->db->where('speaker_id', $row['id']);
$final = $this->db->get()->result_array();
$data[] = array_merge($row, $final);
}
return $data;
}
}