PHP:从对象中获取数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4392704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:55:33  来源:igfitidea点击:

PHP: Getting data out of an object

phpobject

提问by christina

How can I get the user_nicenamefrom this object?

我怎样才能user_nicename从这个对象中得到?

BP_User Object
(
    [data] => stdClass Object
        (
            [ID] => 1
            [user_login] => NICENICE
            [user_pass] => $P$BwLHvV7zxcZZ/zW7MY0NXNSmANP.U5.
            [user_nicename] => NICENAME
            ...

And where can I find resources to learn this?

我在哪里可以找到学习这个的资源?

回答by Pekka

$variable->data->user_nicename

should work.

应该管用。

回答by Shiv Singh

You can print by another way also

您也可以通过其他方式打印

foreach($result->data as $newdata) //$result is variable that store raw data 
{
printf("name: %s, Pass: %s, nicename: %s <br/>", $newdata->user_login, $newdata->user_pass, $newdata->user_nicename);
}

Result will be

结果将是

name:NICENICE , Pass:$P$BwLHvV7zxcZZ/zW7MY0NXNSmANP.U5., nicename:NICENAME