我正在使用Laravel 4.2。这可能很简单。 当我使用 ->get() 从eloquent模型获取结果时,我会得到这种类型的结果
[{"name":"JOHN","tel":"12345"},{"name":"JANE","tel":"67890"}]
我想转换成这种格式。
[["JOHN","12345"],["JANE","67890"]]
我一直在苦恼这个问题,不知道要搜索什么关键词。
使用map()
集合方法和array_values()
函数。我刚刚测试过,它完美运行:
$collection->map(function ($i) {
return array_values($i);
})->toArray();
array_map
:array_map(function ($i) {
return array_values($i);
}, $collection->toArray());
each
方法。尽管@Alexey
的回答很好。
https://laravel.com/docs/4.2/eloquent#collections
$collection->each(function ($i) {
return array_values($i);
})->toArray();