0

i have table (tag).. i want to select all tags in this table and return it as single array where tag_id = index and tag_name = value like this array

array(
            3 => 'Hazel Grouse',
            4 => 'Common Quail',
            5 => 'Common Pheasant',
            6 => 'Northern Shoveler',
            7 => 'Greylag Goose',
            8 => 'Barnacle Goose',
            9 => 'Lesser Spotted Woodpecker',
            10 => 'Eurasian Pygmy-Owl',
            11 => 'Dunlin',
            13 => 'Black Scoter',
)

tags return like this multi D array

Array
(
    [0] => Array
        (
            [tag_id] => 3
            [tag_name] => Hazel Grouse
        )

    [1] => Array
        (
            [tag_id] => 4
            [tag_name] => Common Quail
        )

this is query code

 function get_alltags() {
        $this->db->select('tag_id');
        $this->db->select('tag_name');
        $result = $this->db->get('d_tag');
     return $result->result_array();
    }
    $alltags = $this->tag->get_alltags();
        echo "<pre>";
        print_r($alltags);
        echo "</pre>";
        exit;
user1080247
  • 1,076
  • 4
  • 21
  • 51

1 Answers1

2

you can do something like this

$result=array();
$alltags = $this->tag->get_alltags();
foreach($alltags as $k => $v){
$result[$v['tag_id']]=$v['tag_name'];}
echo "<pre>";
print_r($result);
Karan Thakkar
  • 1,492
  • 2
  • 17
  • 24