Php提取对象变量而不循环对象本身
您好,我有这个对象:
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);它打印出我粘贴的对象。
hi i have this object:
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"
}
}
how can i retrieve for example object->username without cycling the object?
thx
[EDITED]
this is the little piece of code i have:
$user = $this->model_user->populateBy($id = '12');
var_dump($user);
echo $user->username ; // error:Trying to get property of non-object non object
doing var_dump($user); it prints out the object i pasted up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
get_object_vars()
是你需要什么。但我不确定我是否理解这个问题;如果您想要用户名,只需执行
$Object->username
即可。I think
get_object_vars()
is what you need.I'm not sure I understand the question though; if you want the username you can just do
$Object->username
..