Codeigniter generate simple array from database

2019-08-27 19:43发布

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条回答
戒情不戒烟
2楼-- · 2019-08-27 20:13
$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

查看更多
登录 后发表回答