使用以下代码
$matchs = DiraChatLog::where('status','=','Match')->whereBetween('date_access', [$request->from, $request->to])->get();
foreach ($matchs as $key => $match) {
$array[] = [
$match->status => $match->date_access,
];
}
dd($array);
现在我想将4个数组合并为1 ..我该怎么做?我的输出应为array:1> date => value
我已经尝试过array_merge()和array_push()并且它没有工作
答案 0 :(得分:0)
例如使用spl
中的递归数组迭代器$array = array(array(1,2,3),array(5,6,7),array(8,9,10));
$mergedArray = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
foreach ($mergedArray as $a) {
echo $a; // [1,2,3,4,5,6,7,8,9,10]
}
这应该足够了。
答案 1 :(得分:0)
这是你如何使用array_merge()。
$arr = array(
0 => array(1 ,2 ,3),
1 => array(4, 5, 6),
2 => array(7, 8, 9)
);
$allInOne = array();
foreach ($arr as $value) {
$allInOne = array_merge($allInOne, $value);
}
var_dump($allInOne); // the output [1,2,3,4,5,6,7,8,9]
This code will merge you all arrays in one this is just what you want i guess