SamueLL
SamueLL

Reputation: 5

Codeigniter generate simple array from database

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 :)

Upvotes: 0

Views: 1872

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219938

$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

Upvotes: 2

Related Questions