diff --git a/src/Array/dropWhile.php b/src/Array/dropWhile.php index ce62b5f..36020df 100644 --- a/src/Array/dropWhile.php +++ b/src/Array/dropWhile.php @@ -40,11 +40,13 @@ function dropWhile(array $array, callable $predicate): array $count = \count($array); $length = 0; $index = \key($array); - while ($length <= $count && $predicate($array[$index], $index, $array)) { + $value = \current($array); + while ($length <= $count && $predicate($value, $index, $array)) { array_shift($array); \reset($array); $length++; $index = \key($array); + $value = \current($array); } return $array; diff --git a/tests/Array/DropWhileTest.php b/tests/Array/DropWhileTest.php index 997f761..50bef5a 100644 --- a/tests/Array/DropWhileTest.php +++ b/tests/Array/DropWhileTest.php @@ -25,5 +25,25 @@ public function testDropWhile() $this->assertSame([['user' => 'pebbles', 'active' => false]], dropWhile($users, function ($user) { return $user['active']; })); + + $lines = [ + 'Processing report:', + 'Processed: 1', + 'Successful: 1', + '', + '', + ]; + + $lines = dropWhile($lines, static function ($x) { + return trim((string) $x) !== ''; + }); + + self::assertEquals(['', ''], $lines); + + $lines = dropWhile($lines, static function ($x) { + return trim((string) $x) === ''; + }); + + self::assertEmpty($lines); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy