我得到一个API调用响应,通过var_export
生成此输出:
stdClass::__set_state(array(
'message-count' => '1',
'messages' =>
array (
0 =>
stdClass::__set_state(array(
'to' => '23408234',
'message-id' => '023425F8',
'status' => '0',
'remaining-balance' => '152.26940000',
'message-price' => '0.0530',
'network' => '7432',
)),
),
))
如何访问此内容?
我试过这些无济于事:
$response->message-count
$response['message-count']
$response->messages[0]->to
答案 0 :(得分:1)
问题是,您的媒体资源中包含相同的字符(短划线:-
),不允许使用variable name:
[A-ZA-Z_ \ x7f- \ XFF] [A-ZA-Z0-9_ \ x7f- \ XFF] *
因此,要仍然能够访问它,您必须使用complex curly syntax:
$object->{"property-name"}