我用的是拉拉维尔4.2。这可能很简单。当我使用->get()从雄辩的模型中得到结果时,我得到了这种结果
[{"name":"JOHN","tel":"12345"},{"name":"JANE","tel":"67890"}]我想转换成这种格式
[["JOHN","12345"],["JANE","67890"]]我一直在努力解决这个问题,我不知道要搜索哪个确切的关键字。
发布于 2018-02-21 17:02:30
使用map()集合方法和array_values()。刚刚测试了这个,它运行得很好:
$collection->map(function ($i) {
return array_values($i);
})->toArray();在4.2中使用array_map
array_map(function ($i) {
return array_values($i);
}, $collection->toArray());发布于 2018-02-21 17:31:44
https://laravel.com/docs/4.2/eloquent#collections
这可能是一种较短的方法,因为each方法也适用于集合,尽管@Alexey答案很好。
$collection->each(function ($i) {
return array_values($i);
})->toArray();https://stackoverflow.com/questions/48911451
复制相似问题