我有这段代码,我只是不知道如何输出视图中的每个项目,例如名字、姓氏和用户名。
controller
{
$selected_users = array(
'username' => $username,
'firstname' => 'peter',
'lastname' => 'Sample'
);
$users = json_decode($this->session->userdata('users'), true);
$users[] = $selected_users;
$this->session->set_userdata('users', json_encode($users));
$this ->load->view('db_control\sess');
}
view:
$username = $this->session->userdata('users');
echo $username;
but it output all of it
output of this code is
[{"username":"newtest1","firstname":"newtest1","lastname":"newtest1"},{"username":"sample_beth","firstname":"sample_beth","lastname":"sample_beth "},{"username":"default","firstname":"default","lastname":"default"}]
这是正确的,但我想输出用户名、姓氏和名字,但仍然是所有记录