如何从object(stdClass)获取值? [英] How do I get the value from object(stdClass)?

查看:931
本文介绍了如何从object(stdClass)获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PHP,我必须以以下格式解析输入到我的代码中的字符串:

Using PHP, I have to parse a string coming to my code in a format like this:

object(stdClass)(4) { 
    ["Title"]=> string(5) "Fruit" 
    ["Color"]=> string(6) "yellow" 
    ["Name"]=> string(6) "banana" 
    ["id"]=> int(3) 
}

我确定有一个简单的解决方案,但是我似乎找不到...如何获取颜色和名称?

I'm sure there's a simple solution, but I can't seem to find it... how to get the Color and Name?

非常感谢.

推荐答案

您可以执行:$obj->Title等.

或者您可以将其转换为数组:

Or you can turn it into an array:

$array = get_object_vars($obj);

这篇关于如何从object(stdClass)获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆