Codeigniter generate simple array from database

爱⌒轻易说出口 提交于 2019-12-25 05:02:04

问题


i have database with two values id and val so i want to ask how i can generate simple array like this

  array('value', 'value2', 'value3'...); 

I have

  $query = $this->db->query('SELECT val FROM table');
  echo $query->result_array();

But it will result something like that:

  Array
  (
      [0] => Array
          (
              [val] => value
          )

      [1] => Array
          (
              [val] => value2
          )
  )

And i want it in one array so please if you can help me. Thanks for all answers :)


回答1:


$query = $this->db->query('SELECT val FROM table')->result_array();

$array = array();

foreach ( $query as $key => $val )
{
    $temp = array_values($val);
    $array[] = $temp[0];
}

See it here in action: http://viper-7.com/tPd7zN



来源:https://stackoverflow.com/questions/11163172/codeigniter-generate-simple-array-from-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!