我正试图从子阵列中获取第一个元素。我的结果集合中所需的数据如下所示:
#attributes:array:11 [▼
"id" => 1
"title" => "Eerst nieuwsbericht voor Jochen"
"content" => "<p>Dit is een test</p>\n"
"tags" => ""
"images" => "[2,3,4,1]"
"social_media" => ""
"publish_date" => "2015-08-27 01:40:17"
"created_at" => "2015-08-27 13:40:17"
"updated_at" => "2015-08-27 13:40:17"
"slug" => "eerst-nieuwsbericht-voor-jochen"
"files" => array:4 [▼
2 => array:11 [▼
"id" => 2
"parent_id" => 0
"type" => "file"
"path" => "/uploads/flyfish"
"name" => "05-vogelkers1-E2.jpg"
"file_type" => "jpg"
"size" => 162936
"width" => 1024
"height" => 768
"created_at" => Carbon {#368 ▶}
"updated_at" => Carbon {#338 ▶}
]
3 => array:11 [▶]
4 => array:11 [▶]
1 => array:11 [▶]
]
]
我想从子数组'files'中的第一个元素中获取'name'。这是否有速记符号?
我可以用
获得我所需的结果$newsDetail->files[2]['name']
但后来我需要知道键2实际上是数组'files'中的第一个键。
答案 0 :(得分:0)
答案 1 :(得分:0)
简单地说:
current($newsDetail['files']);