簡體   English   中英

Codeigniter選擇結果數組格式

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM