【发布时间】:2020-05-28 06:27:39
【问题描述】:
我需要从所有这些对象类中获取[text] 的值。
我可以从数组中获取值但是从数组中的这些类对象中,我无法获取[text] 的值。
任何帮助将不胜感激。
Array
(
[0] => stdClass Object
(
[text] => time
[tr] => Array
(
[0] => stdClass Object
(
[text] => while
[syn] => Array
(
[0] => stdClass Object
(
[text] => when
)
)
)
[1] => stdClass Object
(
[text] => occasion
[syn] => Array
(
[0] => stdClass Object
(
[text] => moment
)
[1] => stdClass Object
(
[text] => day
)
[2] => stdClass Object
(
[text] => date
)
)
)
)
)
)
【问题讨论】:
-
请发布您尝试过的预期结果+代码............
-
array[0]->text是你所需要的 -
这实际上是一个基于 api 的结果,所以代码很大。我使用 json decode 输出这个结果 var_dump( json_decode($myArray));然后我使用了 print_r($myArray->response; 但它给出了我上面的结果。虽然我想要第一个数组 [text] => time 中的“text”值,但我想要所有的“text”值。
-
@hlfrmn 还有
$array[0]->tr[0]->text、$array[0]->tr[1]->text,$array[0]->tr[0]->syn[0]->text`,等等。 -
要获得所有这些,您可能需要编写一个递归函数。