[
"bob" => $books
"maria" => $otherBooks
]至
[
[
name => "bob"
data => $books
],
[
name => "maria"
data => $otherBooks
]
]发布于 2020-07-31 21:27:03
您可以使用map,map采用$item,$key是您的输入数组的键值,作为闭包的参数。如果你将它们映射到预期的数组结构,这应该是可行的。
$result = collect([
'bob' => $books
'maria' => $otherBooks
])->map(function ($item, $key) {
return [
'name' => $key,
'data' => $item,
]
});发布于 2020-07-31 21:30:35
使用集合可以很容易地做到这一点。
collect([
"bob" => $books
"maria" => $otherBooks
])->map(function ($books, $name) {
return [
'name' => $name,
'data' => $books
];
});https://stackoverflow.com/questions/63192500
复制相似问题