我有一个我似乎无法正常访问的数组,一直试图回显地址。它被称为$user
,这里是print_r:
Array(
[0] => stdClass Object
(
[id] => 1
[firstname] => Casper
[lastname] => *lastname*
[email] => someEmail
[username] => aUsername
[password] => *encrypted password*
[address] => myAddress
[address2] =>
[city] =>
[state] =>
[zipcode] => 1111
[join_date] => current timestamp
)
)
1
这是在codeigniter,到目前为止我已经尝试过:
echo $user['address'];
echo $user->address;
他们两个都没有运气。任何帮助都非常适合
答案 0 :(得分:5)
你有一个多维数组,第一个索引是0,也在你拥有该对象的第一个索引中。访问您需要使用->
你必须像给定的代码一样回应:
echo $user[0]->address;