如果我们有一个关联数组如何打印值[关闭]

I am working in codeigniter. Structure of my array is

    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
        )

)

I want to print the value of arrays.

Use foreach for access all

foreach ($array as $values)
{
   foreach ($values as $value)
   {
      echo $value;
   }
}

Or direct access:

$array[0]->{1};
$array[0]->{2};
$array[1]->{5};
etc..

Usage:

$array[ARRAY INDEX]->{OBJECT INDEX};

As soon as they are not arrays but objects, you need to use

$arr[0]->{0}

form.

Suppose your array is in the variable $arr. Then use it:

$i = 0;
foreach($arr as $array){
 echo $array[$i];
 $i++;
}

OR you can do this:

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

You can get data using

$arr[0]->{0}

OR

$arr[0]->{'0'}

stdClass is php's generic empty class, kind of like Object in Java or object in Python. It is useful for anonymous objects, dynamic properties, etc.

So its not array its an object. you will have to use object operator (->)

check below post

stdClass Object foreach PHP