Take the 2-minute tour ×

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:

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

share|improve this question

1 Answer 1

up vote 0 down vote accepted
$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

share|improve this answer
Your demo appears to be expired/empty. –  Sparky Mar 7 '13 at 8:51

Your Answer


