【发布时间】:2011-09-13 12:00:26
【问题描述】:
嗨,我有这个对象:
object(stdClass)#27 (1) {
[0]=> object(stdClass)#26 (6){
["_id"]=> object(MongoId)#24 (1) {
["$id"]=> string(24) "4e6ea439caa47c2c0c000000"
}
["username"]=> string(16) "wdfkewkghbrjkghb" ["email"]=> string(24) "wdhbfjkwhegerg@€rg.efg" ["password"]=> string(32) "4297f44b13955235245b2497399d7a93" ["slug"]=> string(16) "wdfkewkghbrjkghb" ["insert_datetime"]=> string(19) "2011-09-13 12:09:49"
}
}
如何在不循环对象的情况下检索例如对象->用户名?
谢谢
[编辑]
这是我的一小段代码:
$user = $this->model_user->populateBy($id = '12');
var_dump($user);
echo $user->username ; // error:Trying to get property of non-object non object
正在做 var_dump($user);它打印出我粘贴的对象。
【问题讨论】:
-
“循环”对象是什么意思?
$object->username不工作吗? -
“循环对象”是什么意思?你能展示你正在使用的 PHP 代码吗?
-
我想你需要看看 PHP 中的 OOP 参考
-
这个对象从我分配给 $user = $query_result = $object; 的查询返回那么如果我回显 $user->username;它说错误:试图获取非对象的属性
-
while , foreach( $user as $row) { echo $row->username; } 作品
标签: php arrays object cycle extraction