我试图从循环中回显一个数组,但它似乎不起作用。
代码,将值放入数组中:
public function get_language() {
global $db;
$language = $this->get_visit_loc();
$rows = array();
$query = $db->query("SELECT * FROM languages WHERE lang_id = '{$language}'") or die(mysql_error());
if($db->num_rows($query) > 0) {
while($row = $db->fetch_array($query)) {
$rows[] = $row;
}
} else {
$rows['error'] = 'We have some serious Error!';
}
return $rows;
}
如果我调用该函数并尝试回显该数组,它不会返回任何内容。
$lan = $lang->get_language();
echo $lan['lang_id']; //returns nothing.
echo $lan['error']; //Returns an error.
print_r 结果:
Array ( [0] => Array ( [id] => 1 [lang_id] => EE ) )