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


Echo specific array data from multidimensional ray PHP

{
  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->name 时,它只会回显单词 Array

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

如果只有一个,那么$customer['sources']->data[0]->{property}会为你工作。

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

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

试试这个,哈哈:D

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

;-)