db->from("locations"); $th-6ren">
gpt4 book ai didi

mysql - Code-igniter MySql 中的 Json 数组问题

转载 作者:行者123 更新时间:2023-11-30 22:30:06 25 4
gpt4 key购买 nike

下面是我的代码:

    $this->db->select("city_id,loc_id,loc_name");
$this->db->from("locations");
$this->db->group_by("city_id");
$this->db->order_by("city_id", "asc");
$query = $this->db->get();
return json_encode($query->result_array());

它给我的结果如下:

[{"city_id":"1","loc_id":"17","loc_name":"Al Barsha"} {"city_id":"2","loc_id":"12","loc_name":"testt"}]

但我想得到喜欢

{"1":{"17":"Al Barsg","35":"XYZ"},"2":{"123":"ABC","44":"OtherName"}}

我不知道该怎么做?

最佳答案

试试这个

return json_encode(array($query->result_array());

输出

["0":{"city_id":"1","loc_id":"17","loc_name":"Al Barsha"}...

关于mysql - Code-igniter MySql 中的 Json 数组问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34103426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com