You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -401,6 +404,28 @@ The `collapse` method collapses a collection of arrays into a single, flat colle
401
404
402
405
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
403
406
407
+
<aname="method-collapsewithkeys"></a>
408
+
#### `collapseWithKeys()` {.collection-method}
409
+
410
+
The `collapseWithKeys` method flattens a collection of arrays or collections into a single collection, keeping the original keys intact:
411
+
412
+
$collection = collect([
413
+
['first' => collect([1, 2, 3])],
414
+
['second' => [4, 5, 6]],
415
+
['third' => collect([7, 8, 9])]
416
+
]);
417
+
418
+
419
+
$collapsed = $collection->collapseWithKeys();
420
+
421
+
$collapsed->all();
422
+
423
+
// [
424
+
// 'first' => [1, 2, 3],
425
+
// 'second' => [4, 5, 6],
426
+
// 'third' => [7, 8, 9],
427
+
// ]
428
+
404
429
<aname="method-collect"></a>
405
430
#### `collect()` {.collection-method}
406
431
@@ -1288,6 +1313,21 @@ The `intersect` method removes any values from the original collection that are
1288
1313
> [!NOTE]
1289
1314
> This method's behavior is modified when using [Eloquent Collections](/docs/{{version}}/eloquent-collections#method-intersect).
1290
1315
1316
+
<aname="method-intersectusing"></a>
1317
+
#### `intersectUsing()` {.collection-method}
1318
+
1319
+
The `intersectUsing` method removes any values from the original collection that are not present in the given `array` or collection, using a custom callback to compare the values. The resulting collection will preserve the original collection's keys:
1320
+
1321
+
$collection = collect(['Desk', 'Sofa', 'Chair']);
1322
+
1323
+
$intersect = $collection->intersectUsing(['desk', 'chair', 'bookcase'], function ($a, $b) {
1324
+
return strcasecmp($a, $b);
1325
+
});
1326
+
1327
+
$intersect->all();
1328
+
1329
+
// [0 => 'Desk', 2 => 'Chair']
1330
+
1291
1331
<aname="method-intersectAssoc"></a>
1292
1332
#### `intersectAssoc()` {.collection-method}
1293
1333
@@ -1309,6 +1349,29 @@ The `intersectAssoc` method compares the original collection against another col
1309
1349
1310
1350
// ['size' => 'M']
1311
1351
1352
+
<aname="method-intersectassocusing"></a>
1353
+
#### `intersectAssocUsing()` {.collection-method}
1354
+
1355
+
The `intersectAssocUsing` method compares the original collection against another collection or `array`, returning the key / value pairs that are present in both, using a custom comparison callback to determine equality for both keys and values:
0 commit comments