【发布时间】:2016-06-15 14:01:37
【问题描述】:
我有从数据库返回多数组的 foreach 循环 我想将此数组转换为 json 中的多数组,
如何做到这一点?
php 数组示例
Array
(
[0] => Array
(
[it_code] => 2894
[it_quantity] => 300
[it_price] => 0
[it_notes] =>
)
[1] => Array
(
[it_code] => 2894
[it_quantity] => 284
[it_price] => 0
[it_notes] =>
)
[2] => Array
(
[it_code] => 2894
[it_quantity] => 4
[it_price] => 0
[it_notes] =>
)
[3] => Array
(
[it_code] => 2894
[it_quantity] => 3
[it_price] => 0
[it_notes] =>
)
)
我希望返回的 json 是这种格式
[
['2894', 300, 0,''],
['2894', 284, 0,''],
['2894', 4, 0,''],
['2894', 3, 0,''],
['2894', 10, 0, '']
]
我的代码是这样的
$this->db->where("it_parent_item", $parent_id);
$this->db->select("d_items.it_code,d_items_type.it_ty_ar_desc,d_items.it_quantity,d_items.it_price,it_notes");
$this->db->join('d_items_type','d_items_type.it_ty_id=d_items.it_type','left');
$this->db->from("d_items");
$result = $this->db->get()->result_array();
echo "<pre>";
print_r($result);
echo "</pre>";
【问题讨论】:
-
是json_encode() 你在找什么?
-
@Henders,这不会删除
keys(如果这是操作人员正在寻找的),但值得一试。那么,您是否必须删除密钥(it_..)? -
好点,没想过重新格式化...
-
正如你所说,我想在将其转换为 json 之前删除密钥
-
我只想要值
标签: php arrays json codeigniter