我想要一个带有owen键的数组 但是当我试图这样做时,它只返回第一个结果吗?
$query = $this->db->get('users');
if ($query->num_rows() > 0) {
foreach($query->result() as $row) {
$data = array(
'Name'-> $row->name
);
}
$users = $data;
答案 0 :(得分:1)
这应该是,
$data = array();
$query = $this->db->get('users');
if ($query->num_rows() > 0) {
foreach($query->result() as $row) {
$data[] = $row->name;
}
print_r($data);
$users = $data;
答案 1 :(得分:0)
试试这个:
$data = array();
foreach($query->result() as $row) {
array_push($data,array(
'Name'-> $row->name
));
}
$users = $data;