Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 如果有assoc数组,如何打印值_Php_Codeigniter - Fatal编程技术网

Php 如果有assoc数组,如何打印值

Php 如果有assoc数组,如何打印值,php,codeigniter,Php,Codeigniter,我在codeigniter工作。 我的数组的结构是 Array ( [0] => stdClass Object ( [0] => 15 [1] => 14 [2] => 0 [3] => 0 [4] => 0 ) [1] => stdClass Object

我在codeigniter工作。 我的数组的结构是

    Array
    (
    [0] => stdClass Object
        (
            [0] => 15
            [1] => 14
            [2] => 0
            [3] => 0
            [4] => 0
        )

    [1] => stdClass Object
        (
            [0] => 15
            [1] => 14
            [2] => 0
            [3] => 0
            [4] => 0
        )

)

我想打印数组的值。

只要它们不是数组而是对象,您就需要使用

$arr[0]->{0}

表单。

假设数组位于变量
$arr
中。然后使用它:

$i = 0;
foreach($arr as $array){
 echo $array[$i];
 $i++;
}
或者您可以这样做:

echo $arr[1]->0; //and so on

您可以使用

$arr[0]->{0}


stdClass是php的泛型空类,类似于Java中的Object或Python中的Object。它对于匿名对象、动态属性等非常有用

所以它的数组不是一个对象。必须使用对象运算符(->)

检查下面的帖子


使用
foreach
访问所有

foreach ($array as $values)
{
   foreach ($values as $value)
   {
      echo $value;
   }
}
或直接访问: 用法:

$array[ARRAY INDEX]->{OBJECT INDEX};
看看:
$array[0]->{1};
$array[0]->{2};
$array[1]->{5};
etc..
$array[ARRAY INDEX]->{OBJECT INDEX};