I have this array
$data = [ 'admin'=>'1', 'natasha'=>'2', 'demo3'=>'3' ];
When I output it echo json_encode($data);
I get {"admin":"1","natasha":"2","demo3":"3"}
and this how I need it and it works well!
Now I'm trying to loop data from database like this:
$data = array();
foreach(TopicModel::theListofUsers($topic_cat,30) as $row) {
$data[]= array($row->user_name=>$row->user_id);
}
header('Content-Type: application/json');
echo json_encode($data);
But I'm getting this format [{"demo4":"4"},{"demo3":"3"}]
but I need {"admin":"1","natasha":"2","demo3":"3"}
I tried many things, pass strings and convert to array or manipulate array but none of it gave me the proper format. Any idea?