[英]PHP: Get output from StdClass Object
Here is an array of output from a class. 这是一个类的输出数组。 How can I echo
"Custom Field #1" on the screen? 如何在屏幕上echo
“自定义字段#1”?
WPGMZA\CustomFields Object (
[fields] => Array (
[0] => stdClass Object (
[id] => 1
[name] => Custom Field #1
[icon] => address-book-o
[attributes] => {"elementary":"true"}
[widget_type] => dropdown
)
)
)
Having made fields public and therefore accessible you can access array values using [index]
and object properties using ->key
for example $YourClassIntance->fields[0]->id
should return 1 将字段设为公开并因此可访问,您可以使用[index]
和->key
使用对象属性来访问数组值,例如$YourClassIntance->fields[0]->id
应该返回1
If you the keys of the JSON variable attributes
then you could do: 如果您使用JSON变量attributes
的键,则可以执行以下操作:
$keys = array_keys(json_decode($YourClassIntance->fields[0]->attributes, true));
In this case to echo the first key you would do echo $keys[0];
在这种情况下,要回显第一个键,您可以执行echo $keys[0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.