从多维射线PHP回应特定的数组数据

时间:2015-03-10 01:38:37

标签: php multidimensional-array

{
  sources:
  {
    object: "list"
    total_count: 1
    has_more: false

    data:
    [
      {
         id: card_15ebjVE0mF1nHaPGVYigZadr
         name: "John Doe"
       }
    ]
 },
 default_source: "card_15ebjVE0mF1nHaPGVYigZadr"
}

我试图回应出“John Doe”这个名字而已。我可以很好地回应$ customer [sources]数组,但是当我尝试回显$ customer [sources] - > data->命名时,它只是回显一下Array这个词

2 个答案:

答案 0 :(得分:2)

$customer[sources]->data是一个对象数组。您可以通过其密钥访问特定对象。

如果只有一个,那么$customer['sources']->data[0]->{property}将适合您。

如果有多个,则需要迭代数组:

foreach($customer['sources']->data as $item){
    echo $item->name;
}

答案 1 :(得分:0)

试试这个,哈哈:D

$string = ...data from your file...
$a = exlode('name: "',$string);
$b = explode('"',$a[1]);
$yourName = $b[0];

- )