I am trying to make and return json data using codeigniter. I want to receive that data in this format
[
{
'title': 'this is title',
'desc': 'THis is desc'
},
{
'title': 'this is title',
'desc': 'THis is desc'
}
]
But I am receiving it this way
[[{"title":"this is title","desc":"this is desc"}],[{"title":"this is title","description":"this is desc"}]]
how can I change this format to above one?
here is my code
public function v1 () {
$this->load->model('model_jokes');
$jokes = $this->model_jokes->readJokes();
$arr = array();
foreach ($jokes as $joke) {
$arr[] = array(
array(
'title' => $joke->title,
'description' => $joke->joke
)
);
}
echo json_encode($arr);
}
Make the assignment inside
foreachasOtherwise you will get a multi-dimensional array for each
$joke.