Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在stdClass对象中获取变量值?_Php_Stdclass - Fatal编程技术网

Php 如何在stdClass对象中获取变量值?

Php 如何在stdClass对象中获取变量值?,php,stdclass,Php,Stdclass,我从一个stdClass格式的API得到一个返回的结果。我对这类数据一无所知。所以这里看起来像: object(stdClass)#41 (1) { ["return"]=> object(stdClass)#42 (7) { ["afterPayOrderReference"]=> string(32) "d4ab78df6ab2ef84194dd1c1d66240b8" ["checksum"]=> strin

我从一个stdClass格式的API得到一个返回的结果。我对这类数据一无所知。所以这里看起来像:

object(stdClass)#41 (1) { 
   ["return"]=> 
       object(stdClass)#42 (7) {
          ["afterPayOrderReference"]=> string(32) "d4ab78df6ab2ef84194dd1c1d66240b8"
          ["checksum"]=> string(32) "4f8826a99e9c0a67e578d04b6a625117" 
          ["resultId"]=> int(0) 
          ["statusCode"]=> string(1) "A" 
          ["timestampIn"]=> float(1408533108515) 
          ["timestampOut"]=> float(1408533113616) 
          ["transactionId"]=> int(129525) 
       } 
}
我需要的是检索statusCode值。我试着在我读到的一篇文章中这样做:

$array = (array) $stringResult;
$array[0]->statusCode;

但它不起作用。请,有人用最简单的方式给我解释一下,因为这对我来说真的很新鲜。谢谢。

对象属性是通过
->
操作符访问的。只要做:

echo $stringResult->return->statusCode;
如果您想要一个数组,您可以这样访问,因为该数组包含一个对象:

$array = (array)$stringResult;
echo $array['return']->statusCode;

它是一个对象数组,所以正如您调用数组元素一样

echo $stringResult["return"]->statusCode