@@ -786,13 +786,24 @@ public function only($keys)
786
786
}
787
787
788
788
/**
789
- * Get and remove the last item from the collection.
789
+ * Get and remove the last N items from the collection.
790
790
*
791
+ * @param int $count
791
792
* @return mixed
792
793
*/
793
- public function pop ()
794
+ public function pop ($ count = 1 )
794
795
{
795
- return array_pop ($ this ->items );
796
+ if ($ count === 1 ) {
797
+ return array_pop ($ this ->items );
798
+ }
799
+
800
+ $ results = [];
801
+
802
+ foreach (range (1 , $ count ) as $ item ) {
803
+ array_push ($ results , array_pop ($ this ->items ));
804
+ }
805
+
806
+ return new static ($ results );
796
807
}
797
808
798
809
/**
@@ -939,13 +950,24 @@ public function search($value, $strict = false)
939
950
}
940
951
941
952
/**
942
- * Get and remove the first item from the collection.
953
+ * Get and remove the first N items from the collection.
943
954
*
955
+ * @param int $count
944
956
* @return mixed
945
957
*/
946
- public function shift ()
958
+ public function shift ($ count = 1 )
947
959
{
948
- return array_shift ($ this ->items );
960
+ if ($ count === 1 ) {
961
+ return array_shift ($ this ->items );
962
+ }
963
+
964
+ $ results = [];
965
+
966
+ foreach (range (1 , $ count ) as $ item ) {
967
+ array_push ($ results , array_shift ($ this ->items ));
968
+ }
969
+
970
+ return new static ($ results );
949
971
}
950
972
951
973
/**
@@ -1401,6 +1423,7 @@ public function pad($size, $value)
1401
1423
*
1402
1424
* @return \ArrayIterator
1403
1425
*/
1426
+ #[\ReturnTypeWillChange]
1404
1427
public function getIterator ()
1405
1428
{
1406
1429
return new ArrayIterator ($ this ->items );
@@ -1411,6 +1434,7 @@ public function getIterator()
1411
1434
*
1412
1435
* @return int
1413
1436
*/
1437
+ #[\ReturnTypeWillChange]
1414
1438
public function count ()
1415
1439
{
1416
1440
return count ($ this ->items );
@@ -1456,6 +1480,7 @@ public function toBase()
1456
1480
* @param mixed $key
1457
1481
* @return bool
1458
1482
*/
1483
+ #[\ReturnTypeWillChange]
1459
1484
public function offsetExists ($ key )
1460
1485
{
1461
1486
return isset ($ this ->items [$ key ]);
@@ -1467,6 +1492,7 @@ public function offsetExists($key)
1467
1492
* @param mixed $key
1468
1493
* @return mixed
1469
1494
*/
1495
+ #[\ReturnTypeWillChange]
1470
1496
public function offsetGet ($ key )
1471
1497
{
1472
1498
return $ this ->items [$ key ];
@@ -1479,6 +1505,7 @@ public function offsetGet($key)
1479
1505
* @param mixed $value
1480
1506
* @return void
1481
1507
*/
1508
+ #[\ReturnTypeWillChange]
1482
1509
public function offsetSet ($ key , $ value )
1483
1510
{
1484
1511
if (is_null ($ key )) {
@@ -1494,6 +1521,7 @@ public function offsetSet($key, $value)
1494
1521
* @param string $key
1495
1522
* @return void
1496
1523
*/
1524
+ #[\ReturnTypeWillChange]
1497
1525
public function offsetUnset ($ key )
1498
1526
{
1499
1527
unset($ this ->items [$ key ]);
0 commit comments