[英]codeigniter select result array format
我有以下代码:
$query = $this->db->select( 'cat_id' )
->from( 'products_cat' )
->where('product_id',$id)
->get()
**->result_array();**
return $query;
它是以下格式的返回值:
Array ( [0] => Array ( [cat_id] => 2 ) [1] => Array ( [cat_id] => 3 ) [2] => Array ( [cat_id] => 5 ) )
我希望它返回像Array(2,3,5)
这样的简单数组
(没有数组内部的数组,也没有“ cat_id”索引)
我需要更改什么?
替换您的return $query;
使用此return array_map( function( $data ) { return $data['cat_id']; }, $query );
result_array()返回一个json_decoded数组。 使用json_encode($query)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.