在laravel中调用2维数组中的元素

问题描述 投票:1回答:2

items: array:2 [▼

0 => Tour {#229 ▼
  #table: "tour"
  #...
  #attributes: array:12 [▼
    "id" => 6
    "name" => "Nha Trang Tour"
    "price" => 3500000.0
    "price_promotion" => 0.0
    "id_package" => 4
    "id_location" => 8
    "start_time" => "2018-01-27"
    "end_time" => "2018-01-28"
    "star" => 4.0
    "description" => "Funny"
    "created_at" => null
    "updated_at" => "2017-12-29 00:00:00"
  ]
  #...
}
1 => Tour {#230 ▶}

我需要在“#items”中的2个数组0和1中调用2个id_location

($sale['items']->id_location);

($sale->id_location);

但不能接受,而且我使用

($sale[0]->id_location);

然后成功,但只得到一个

谢谢你的帮助

laravel
2个回答
1
投票

使用pluck()方法,如果它是一个集合,或使用array_pluck,如果它是一个数组:

$sale->pluck('id_location');
array_pluck($sales, 'id_location');

0
投票

非常感谢你:D,我成功地拿了桌子,但是当我使用视图时,情况是:查看[“Weekend Package”]而不是Weekend Package enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.