通过数字键访问PHP对象中的数据

时间:2012-10-05 21:44:22

标签: php solr

我有一个solr查询输出“突出显示”在一个对象我不知道如何访问它的数据。让我们说我想回到“Black& Red”我试过了:

$object->{10304}->color_source_name[0];
$object->{'10304'}->color_source_name[0];

两者都没有给我任何东西。如何访问数据?

这是我在下面引用的对象:

print_r($object);

SolrObject Object
(
[10304] => SolrObject Object
    (
        [color_source_name] => Array
            (
                [0] => Black & Red
            )

        [description] => Array
            (
                [0] =>  with their true identity safely masked.Midcalf Lucha Red
            )

        [name] => Array
            (
                [0] => Sock It To Me Lucha Red Midcalf
            )

        [color] => Array
            (
                [0] => Red
            )

    )

[4075] => SolrObject Object
    (
        [color_source_name] => Array
            (
                [0] => Beige/Red
            )

        [description] => Array
            (
                [0] => Very sheer with red tops and Cuban heels and an oh-so-sexy red backseam.  These are designed
            )

        [name] => Array
            (
                [0] => Two-Tone Red Cuban-Heeled Stockings
            )

        [color] => Array
            (
                [0] => Red
            )

    )

1 个答案:

答案 0 :(得分:3)

根据http://php.net/manual/en/class.solrobject.php SolrObject实施ArrayAccess,您可以使用方括号,例如。

echo $object[4075]['colour_source_name'][0];