0

我正在尝试从我的数据库中打印选定的产品名称,但是我看到的只是单词“Array”而不是产品名称。它显示的次数与其找到的产品数量一样多,并且该数字是正确的,但它只显示“数组”......

这是我的代码:

public function lookup($product)
    {

        $camera = $this->db->query("SELECT name FROM products WHERE type = 'Camera' ");

        $laptop = $this->db->query("SELECT name FROM products WHERE type = 'Laptop' ");


        $data = array();

        switch($product)
        {
            case 'camera' : 
            foreach ($camera->result() as $row)
            {
                $entry = array();
                $entry['name'] = $row->name;
                $data[] = $entry;
            }
            return $data; break;

            case 'laptop' :
            foreach ($laptop->result() as $row)
            {
                $entry = array();
                $entry['name'] = $row->name;
                $data[] = $entry;
            }
            return $data; break;

        }   
    }
4

1 回答 1

2

你想echo阵列吗?您可能应该尝试var_dump($array_var);或使用循环,例如foreach遍历数组值并打印/回显每个值。

于 2012-10-19T17:52:08.847 回答