簡體   English   中英

如何在Codeigniter中將數組與結果合並?

[英]How to merge array with result in Codeigniter?

我在Codeigniter中有此代碼,但是不知何故array_merge不想工作,如何將數組合並到結果中?

$categories = $this->get_categories();

    $data = array();

    foreach ($categories as $index) {
        $this->db->select('*');
        $this->db->from('questions');
        $this->db->where('category', $index);
        $this->db->order_by('id','RANDOM');
        $this->db->limit(3);
        $query = $this->db->get();

        array_merge_recursive($data, $query->result());


    }

    return $data;

您需要將array_merge_recursive()的結果保存到$data字符串中:

$data = array_merge_recursive($data, $query->result());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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