Codeigniter:从单个列获取所有值作为数组 [英] Codeigniter: get all values from single column as array

查看:76
本文介绍了Codeigniter:从单个列获取所有值作为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的查询,用于从t中获取单列

Here is my query to get a single column from t

$sql = "SELECT `id` FROM `loc8_groups`";
 $query = $this->db->query($sql);
 print_r($query>result());

它以这种方式产生数组结果.

Its produce array result like this way.

Array
(
    [0] => stdClass Object
        (
            [id] => 1
        )

    [1] => stdClass Object
        (
            [id] => 2
        )

    [2] => stdClass Object
        (
            [id] => 3
        )

)

但是我想要结果作为包含所有ids的单个关联数组.

But i want result as single associative array that contains all the ids.

推荐答案

尝试以下代码:

$sql = "SELECT `id` FROM `loc8_groups`";
$query = $this->db->query($sql);
$array1=$query>result_array();
$arr = array_map (function($value){
    return $value['id'];
} , $array1);
 print_r($arr);

这篇关于Codeigniter:从单个列获取所有值作为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆