dpgbh20688 2013-09-06 19:28 采纳率: 0%
浏览 61
已采纳

Codeigniter活动记录返回单个数组

im returning data back from my db using codeigniter's database class , is there anyway I can put it into the same array without having to do additional array_merge logic after the loop completes?

foreach ($saved_forms[0] as $key => $value) {
     $this->db->select('form_text');
     $this->db->from('form_labels');
     $this->db->where('form_label', $key );
     $query = $this->db->get();

       $form_names  = $query->result_array();
       $form_titles[] = $form_names;

    }

result array

[4] => Array
    (
        [0] => Array
            (
                [form_text] => Participant Name
            )

    )

[5] => Array
    (
        [0] => Array
            (
                [form_text] => Date of Birth
            )

    )

What i want :

 [0] => Array
       (
        [form_text] => Participant Name
        [form_text] => Date of Birth
       )
  • 写回答

4条回答 默认 最新

  • doumen5491 2013-09-06 19:57
    关注

    Try this

    $query = $this->db->select('form_text')
             ->from('form_labels');
             ->where_in('form_label', array_keys($saved_forms[0]));
             ->get();
    
    foreach( $query->result as $label){
       $form_titles[] = $label->form_text;
    }
    

    It will produce a single array with the texts

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 电脑出问题了,说是usbmom注册表没
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网