试图访问php数组中的数据

时间:2014-05-02 12:22:28

标签: php json laravel

如果我将此数组作为json返回:

$events['data']

我明白了:

[
    {
        "id":"3"
    }
]

但是如果我尝试返回id,我会使用以下代码获取Undefined index: id

$events['data']['id']

如何访问该数据?

编辑:在下面添加$ event ['data']的var_dump:

array(1) {
  [0]=>
  array(6) {
    ["id"]=>
    string(15) "299452650179381"
    ["name"]=>
    string(23) "Body of Work Exhibition"
    ["description"]=>
    string(380) "Friday 23rd May - Private view from 6-9pm. Part of Dartmouth Galleries Week.
A group show of 11 artists including Clare Cutts, Aliisa Hyslop, Janet Mitchell, Lynn Muir wooden figures, Jane Ryan OPI Kathryn O'Kell, Sarah Saunders Ceramics, Kate Glanville - Plates and Tiles, Karen James,  EllyMental Jewellery and Elvis the Kat
All work will feature bodies whether human or animal."
    ["cover"]=>
    array(4) {
      ["cover_id"]=>
      string(15) "750312108326721"
      ["source"]=>
      string(101) "https://scontent-b.xx.fbcdn.net/hphotos-prn2/t1.0-9/s720x720/1947331_750312108326721_1639418640_n.jpg"
      ["offset_y"]=>
      int(30)
      ["offset_x"]=>
      int(0)
    }
    ["start_time"]=>
    string(24) "2014-05-23T18:00:00+0100"
    ["end_time"]=>
    string(24) "2014-06-12T17:00:00+0100"
  }
}

1 个答案:

答案 0 :(得分:0)

foreach($events as $v){
$id = $v['id'];
}