使用第一组代码我可以打印数组,但是第二段是为了将数组存储到变量中但是这没有任何建议?数组是空的?
$stmt = $conn->prepare("SELECT admin_name FROM adminuser_tbl");
if ($stmt->execute()) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
下面不工作
$stmt = $conn->prepare("SELECT admin_name, adminuser_id FROM adminuser_tbl");
if ($stmt->execute()) {
$user_list = array();
while ($row = $stmt->fetch()) {
$user_list[$row->adminuser_id] = $row->admin_name;
}
}
如果我打印第一段的数组结果,它们都设置为 [0]???
Array ( [admin_name] => User1 [0] => User1 ) Array ( [admin_name] => User2 [0] => User2 ) Array ( [admin_name] => User3 [0] => User3 ) Array ( [admin_name] => User4 [0] => User4 )