本文介绍了Codeigniter从数据库生成简单数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个值id和val的数据库,所以我想问我可以如何生成简单的数组
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'...);
我有
$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 :)
推荐答案
$query = $this->db->query('SELECT val FROM table')->result_array();
$array = array();
foreach ( $query as $key => $val )
{
$temp = array_values($val);
$array[] = $temp[0];
}
查看此处的操作:
这篇关于Codeigniter从数据库生成简单数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!