0

我有一个像这样的数组:

stdClass Object
(
    [223] => Array
        (

            [0] => stdClass Object
                (
                    [tribeName] => TTTT
                    [tribeid] => 31
                    [numusers] => 10
                    [dateCreated] => 2012-05-28 18:30:34
                )

            [1] => stdClass Object
                (
                    [tribeName] => KKKKK
                    [tribeid] => 32
                    [numusers] => 11
                    [dateCreated] => 2012-05-28 18:32:12
                )

            [2] => stdClass Object
                (
                    [tribeName] => RRRR
                    [tribeid] => 33
                    [numusers] => 5
                    [dateCreated] => 2012-05-28 18:53:17
                )

            [3] => stdClass Object
                (
                    [tribeName] => mytehhhhhst2
                    [tribeid] => 34
                    [numusers] => 4
                    [dateCreated] => 2012-05-28 18:56:15
                )

            [4] => stdClass Object
                (
                    [tribeName] => yog
                    [tribeid] => 58
                    [numusers] => 1
                    [dateCreated] => 2012-06-01 12:32:47
                )

            [5] => stdClass Object
                (
                    [tribeName] => newFunc
                    [tribeid] => 63
                    [numusers] => 1
                    [dateCreated] => 2012-06-01 12:45:01
                )

            [6] => stdClass Object
                (
                    [tribeName] => Jghj
                    [numusers] => 0
                    [tribeid] => 
                )
        )
)

这里,223 是键值,每次都是新的。我将其作为键($array)访问。我会得到 223 的价值。但是我怎样才能访问它的值,例如tribeName?请帮助我。

谢谢。

4

3 回答 3

2

尝试这个

  foreach ($array as $value) {
           foreach($value as $data )
               echo $data->tribeName;
    }
于 2012-06-01T09:42:39.287 回答
0

Try this..

foreach($var as $key => $val)
    {
            $kkv = $var[$key];
            $inarray = $kkv[0];
            print_r($inarray);
            echo $inarray['tribeName'];
    }
于 2012-06-01T11:27:54.213 回答
0

AFAIK,您将不得不遍历数组并手动检查每个元素。当然,您也可以为此编写一个函数。

如果您需要比较整个数组元素,而不仅仅是其中的一个成员,您可以使用array_search来确定键。

于 2012-06-01T09:39:26.410 回答