I am trying to get the following output format from a CI query and subsequent JSON_encode:
{"clients":{"id":"3","name":"Client Number1"},{"id":"2","name":"Client Number2"},{"id":"1","name":"Test Client"},{"id":"4","name":"Test Client2"}}
Combining the small functions in the controller and the model, I am using:
$query = $this->db->query('SELECT id, name FROM clients ORDER BY name ASC');
foreach ($query->result() as $row)
{
$arr['clients'][] = $row;
}
$json = json_encode($arr, JSON_FORCE_OBJECT);
echo $json;
This code outputs (below) which includes the array index values ("1", "2"... etc.) How can I remove these index values from the result? Thanks for any help you may be able to give. This one is not a deal-breaking crisis. I could parse them out on the other side of the transaction... but thought the omniscient SO might know how to do this more elegantly!!
{"clients":{"0":{"id":"3","name":"Client Number1"},"1":{"id":"2","name":"Client Number2"},"2":{"id":"1","name":"Test Client"},"3":{"id":"4","name":"Test Client2"}}}