我正在尝试从我的数据库中打印选定的产品名称,但我看到的只是“数组”而不是产品名称。它显示的次数与它找到的产品数量相同,并且该数字是正确的,但它只显示“数组”......
这是我的代码:
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;
}
}
答案 0 :(得分:2)
您是否尝试echo
阵列?您应该尝试var_dump($array_var);
或使用foreach
之类的循环来遍历数组值并打印/回显每个数组值。