How to loop thru and output values of a variant array object in Php

☆樱花仙子☆ 提交于 2019-12-12 06:38:13

问题


In my Php code I have an array object $myArrayIbject that I want to get its values. I know it is not a one dimensional array. That's what I know for sure.

When I run

echo gettype($myArrayIbject);

It returns Object.

When I run

echo count($myArrayIbject);

It returns 1632.

When I run

var_dump( $myArrayIbject);

It returns

object(variant)#3(0){ }

When I run

variant_get_type($myArrayIbject)

It returns 8209.

The other thing I have observed is that from $myArrayIbject[0] all the way to $myArrayIbject[1631] it returns integer values when I run the below code

for ($i=0; $i< count($myArrayIbject); $i++) {
     echo "Value at ".$i." is ". $myArrayIbject[$i]."<br/>";
}

I know this is not the way to access all its values. I am looking for a way to extract and access all its values.


回答1:


You can use this

foreach($myArrayIbject as $index=>$value)
     echo "Value at ".$index." is ". $value."<br/>";
}


来源:https://stackoverflow.com/questions/42166123/how-to-loop-thru-and-output-values-of-a-variant-array-object-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!