1

我在一个我不知道如何访问它的数据的对象中有一个 solr 查询“突出显示”的输出。可以说我想找回我尝试过的“黑色和红色”:

$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
            )

    )

)

4

1 回答 1

3

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

echo $object[4075]['colour_source_name'][0];
于 2012-10-05T21:48:23.230 回答