模型功能
public function getUserByID($id)
{
$q = $this->db->get_where('users', array('id' => $id), 1);
$user= $q->result();
if($user) {
return $user;
} else {
return false;
}
}
控制器代码
$data['user'] = $this->users_model->getUserByID($id);
查看文件代码
<pre><?php print_r($user); ?></pre>
Array
(
[0] => stdClass Object
(
[id] => 1
[name] => Saleem
[city] => Kuala Lumput
[state] => WP
[postal_code] => 58100
[country] => Malaysia
[phone] => 0123456789
)
)
我怎样才能得到如下结果。
Array
(
[id] => 1
[name] => Saleem
[city] => Kuala Lumput
[state] => WP
[postal_code] => 58100
[country] => Malaysia
[phone] => 0123456789
)
现在我需要将它用作 $user['0']->name; 我想将其用作 $user->name; 请帮我