如何在PHP中访问此数据的成员? [英] How to access the members of this data in PHP?
问题描述
好的.现在我放弃了.我已经玩了几个小时了.
Okay. Now I give up. I have been playing with this for hours.
- 我有一个变量名
$data
. -
变量包含以下内容:(使用
var_export()
提取)
- I have a variable name
$data
. The variable contains these contents: (extracted by using
var_export()
)
array (
'headers' =>
array (
'content-type' => 'multipart/alternative; boundary="_689e1a7d-7a0a-442a-bd6c-a1fb1dc2993e_"',
),
'ctype_parameters' =>
array (
'boundary' => '_689e1a7d-7a0a-442a-bd6c-a1fb1dc2993e_',
),
'parts' =>
array (
0 =>
stdClass::__set_state(array(
'headers' =>
array (
'content-type' => 'text/plain; charset="iso-8859-1"',
'content-transfer-encoding' => 'quoted-printable',
),
'ctype_primary' => 'text',
)),
),
)
我删除了一些不必要的数据.
我怎么可能访问stdClass::__set_state
部分中的值?
How can I possibly access the values within the stdClass::__set_state
section?
我尝试了var_export($data->parts);
,但我得到的只是
I tried var_export($data->parts);
but all I get is
NULL
NULL
推荐答案
该变量是声明的发布方式吗?喜欢:
Is this variable declared the way you posted it? Like:
$data = array(
'headers' =>
array (
…
在这种情况下,我不太确定如何通过$data->headers
访问'headers'
.应该是$data['headers']
,因为它是一个数组,而不是对象.
In that case, I'm not quite sure how you can access 'headers'
via $data->headers
. It should be $data['headers']
, because it is an array, not an object.
进一步, stdClass::__set_state(array('headers' => …))
静态调用类stdClass
的方法 __set_state
.我不知道该方法是什么,但只会将其返回值分配给'parts' => array(0 => ...)
键.
Further down, stdClass::__set_state(array('headers' => …))
statically calls the method __set_state
of the class stdClass
. Whatever this method does I don't know, but only its return value will be assigned to the 'parts' => array(0 => ...)
key.
如果OTOH显示的是 var_dump($data)
的结果,则这是不正确的废话,因为stdClass::__set_state()
永远不会出现在var_dump
中.在您的代码或发布的内容中,有些东西是可疑的,如果看不到更多内容,很难说.
If OTOH what you're showing is the result of var_dump($data)
, then this is incorrect nonsense, since stdClass::__set_state()
would never show up in a var_dump
. Something is fishy either in your code or in what you posted and it's hard to say without seeing more of it.
忽略以上内容,var_export
以这种时髦的方式打印类.
Disregard the above, var_export
prints classes this funky way.
$data['headers']
应该在第一个标头部分执行此操作.再往下走,$data['parts'][0]->headers
应该可以解决问题.
$data['headers']
should do it for the first headers part. Further down, $data['parts'][0]->headers
should do the trick.
这篇关于如何在PHP中访问此数据的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!