Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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_Loops_Stdclass - Fatal编程技术网

如何在PHP中迭代这个stdClass

如何在PHP中迭代这个stdClass,php,loops,stdclass,Php,Loops,Stdclass,你能帮我用循环迭代这个stdClass吗?我只想打印值 stdClass Object ( [GetInfoResult] => stdClass Object ( [string] => Array ( [0] => My Value 1 [1] => My Value 2 [2] => My Value 3 [3] => My Value 4 [4] => My val 5 [5] => My val 6 [6] => My last v

你能帮我用循环迭代这个stdClass吗?我只想打印值

stdClass Object ( [GetInfoResult] => stdClass Object ( [string] => Array ( [0] => My Value 1 [1] => My Value 2 [2] => My Value 3 [3] => My Value 4 [4] => My val 5 [5] => My val 6 [6] => My last val ) ) ) 
例如:

  • 我的价值1
  • 我的价值2
  • 我的价值3
  • 。。。等

要打印的值位于嵌套在对象中的数组中。只需访问阵列并使用
foreach

foreach ($object->GetInfoResult->string as $string) {
    echo $string;
}

@mulquin我以前看过这个页面,但我不能正确地迭代。我不知道是什么问题。你能发布你尝试过的代码吗?非常感谢。是的,我现在可以正确打印了。