<?php
$data1 = [
['name' => 'a'],
['name' => 'b'],
['name' => 'c'],
['name' => 'd'],
['name' => 'e'],
['name' => 'f'],
['name' => 'g'],
];
$data2 = [
['name' => 'a'],
['name' => 'd'],
['name' => 'f'],
];
//想要的结果
$result = [
['name' => 'a', 'checked' => true],
['name' => 'b'],
['name' => 'c'],
['name' => 'd', 'checked' => true],
['name' => 'e'],
['name' => 'f', 'checked' => true],
['name' => 'g'],
];
//请教 以上问题 在 laravel 怎么实现
关于在laravel时里面二维数组根据条件合并
我觉得你还是可以认真看看 Collection 的系列:https://www.laravist.com/series/refactoring-loops-with-collection
collect($data1)->map(function($item) use ($data2) {
if (collect($data2)->contains($item)) {
$item['check'] = true;
}
return $item;
})
一个最快想到的方法