Multiples数组 - 用PHP调用

时间:2017-06-13 20:54:02

标签: php arrays

我想调用我的数组中的值但是我遇到了问题。当它只在一个层面上时,我到达那里。但是当他有2级或3级时,我不能。

这是我的阵列。

    [
    {
    "total": "4",
    "nbPage": 10,
    "color": {
        "reference": "56f50a7e4fhghc8c",
        "name": "Noir"
    },
    "gallery": [
        {
            "thumb": "exemple.png",
            "position": 0,
            "reference": "cfc84f0752adc96b489sdf71195d91a946c5f6d3e8",
            "updatedAt": "2017-06-08T10:04:23+0200"
        }
    ],

以此功能为例,我到达第一点:

<?php echo $vehicules[0]->reference; ?> 

但要打电话,例如“Color&amp; Reference”,我找不到解决方案。我搜索了很多关于这个主题的话题,但是我在2个小时后也在同一步...... 谢谢你!

1 个答案:

答案 0 :(得分:0)

数组中有一个对象,正在寻找:

$vehicules[0]->color // To access the colour object
$vehicules[0]->color->reference // To access the colour reference (56f50a7e4fhghc8c)

要访问图库参考,您可以使用:

$vehicules[0]->gallery[0]->reference // cfc84f0752adc96b489sdf71195d91a946c5f6d3e8

希望这有帮助! :)