引用数组中的常量标识符

时间:2018-02-22 14:38:11

标签: php mysql json multidimensional-array

注意下面的print_r的第三级嵌套中的“[$ t] - > value”。引用没有数字或关联标签的[$ t]的正确方法是什么?

print_r ($breedPHP['breeds']['breed'][1]);
var_dump($breedPHP['breeds']['breed'][1]);

产生

Array ( [$t] => Chinchilla ) //print_r
array(1) { ["$t"]=> string(10) "Chinchilla" } //var_dump

我如何仅返回'Chinchilla'的价值?又如何,我如何引用常量[$ t]?

查询API:

 $br = new Petfinder('xxxxxxxxxxxxxxxxxxxxxxxxx');
    $br->setResponseFormat('json');
    $breedJson = $br->breed_list(array('animal'=>'smallfurry'));
    $breedPHP = json_decode($breedJson, TRUE);
    print_r($breedPHP);

在父数组上输出print_r:

Array ( [@encoding] => iso-8859-1 [@version] => 1.0 [petfinder] => Array ( [@xmlns:xsi] => http://www.w3.org/2001/XMLSchema-instance [breeds] => Array ( [breed] => Array ( [0] => Array ( [$t] => Abyssinian ) [1] => Array ( [$t] => Chinchilla ) [2] => Array ( [$t]
=> Degu ) [3] => Array ( [$t] => Dwarf Hamster ) [4] => Array ( [$t] => Ferret ) [5] => Array ( [$t] => Gerbil ) [6] => Array ( [$t] => Guinea Pig ) [7] => Array ( [$t] => Hamster ) [8] => Array ( [$t] => Hedgehog ) [9] => Array ( [$t] => Mouse ) [10] => Array ( [$t] => Peruvian ) [11] => Array ( [$t] => Prairie Dog ) [12] => Array ( [$t]
=> Rat ) [13] => Array ( [$t] => Rex ) [14] => Array ( [$t] => Short-Haired ) [15] => Array ( [$t] => Silkie / Sheltie ) [16] => Array ( [$t] => Skunk ) [17] => Array ( [$t] => Sugar Glider ) [18] => Array ( [$t] => Teddy ) ) [@animal] => smallfurry ) [header] => Array ( [timestamp] => Array ( [$t] => 2018-02-22T14:03:34Z ) [status] => Array ( [message] => Array ( ) [code] => Array ( [$t] => 100 ) ) [version] => Array ( [$t] => 0.1 ) ) [@xsi:noNamespaceSchemaLocation]
=> http://api.petfinder.com/schemas/0.9/petfinder.xsd ) )

与上面相同的print_r输出,被视为html源(为了方便):

Array
(
    [@encoding] => iso-8859-1
    [@version] => 1.0
    [petfinder] => Array
        (
            [@xmlns:xsi] => http://www.w3.org/2001/XMLSchema-instance
            [breeds] => Array
                (
                    [breed] => Array
                        (
                            [0] => Array
                                (
                                    [$t] => Abyssinian
                                )

                            [1] => Array
                                (
                                    [$t] => Chinchilla
                                )

                            [2] => Array
                                (
                                    [$t] => Degu
                                )

                            [3] => Array
                                (
                                    [$t] => Dwarf Hamster
                                )

                            [4] => Array
                                (
                                    [$t] => Ferret
                                )

                            [5] => Array
                                (
                                    [$t] => Gerbil
                                )

                            [6] => Array
                                (
                                    [$t] => Guinea Pig
                                )

                            [7] => Array
                                (
                                    [$t] => Hamster
                                )

                            [8] => Array
                                (
                                    [$t] => Hedgehog
                                )

                            [9] => Array
                                (
                                    [$t] => Mouse
                                )

                            [10] => Array
                                (
                                    [$t] => Peruvian
                                )

                            [11] => Array
                                (
                                    [$t] => Prairie Dog
                                )

                            [12] => Array
                                (
                                    [$t] => Rat
                                )

                            [13] => Array
                                (
                                    [$t] => Rex
                                )

                            [14] => Array
                                (
                                    [$t] => Short-Haired
                                )

                            [15] => Array
                                (
                                    [$t] => Silkie / Sheltie
                                )

                            [16] => Array
                                (
                                    [$t] => Skunk
                                )

                            [17] => Array
                                (
                                    [$t] => Sugar Glider
                                )

                            [18] => Array
                                (
                                    [$t] => Teddy
                                )

                        )

                    [@animal] => smallfurry
                )

            [header] => Array
                (
                    [timestamp] => Array
                        (
                            [$t] => 2018-02-22T03:51:30Z
                        )

                    [status] => Array
                        (
                            [message] => Array
                                (
                                )

                            [code] => Array
                                (
                                    [$t] => 100
                                )

                        )

                    [version] => Array
                        (
                            [$t] => 0.1
                        )

                )

            [@xsi:noNamespaceSchemaLocation] => http://api.petfinder.com/schemas/0.9/petfinder.xsd
        )

)

0 个答案:

没有答案