Skip to content

Commit 3363250

Browse files
authored
improve doctype of forget/except method of Arr class (#41508)
1 parent 16636ca commit 3363250

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Illuminate/Collections/Arr.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static function undot($array)
142142
* Get all of the given array except for a specified array of keys.
143143
*
144144
* @param array $array
145-
* @param array|string $keys
145+
* @param array|string|int|float $keys
146146
* @return array
147147
*/
148148
public static function except($array, $keys)
@@ -256,7 +256,7 @@ public static function flatten($array, $depth = INF)
256256
* Remove one or many array items from a given array using "dot" notation.
257257
*
258258
* @param array $array
259-
* @param array|string $keys
259+
* @param array|string|int|float $keys
260260
* @return void
261261
*/
262262
public static function forget(&$array, $keys)

tests/Support/SupportArrTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public function testExcept()
149149
$this->assertEquals(['name' => 'taylor'], Arr::except($array, 'framework'));
150150
$this->assertEquals(['name' => 'taylor', 'framework' => ['name' => 'Laravel']], Arr::except($array, 'framework.language'));
151151
$this->assertEquals(['framework' => ['language' => 'PHP']], Arr::except($array, ['name', 'framework.name']));
152+
153+
$array = [1 => 'hAz', 2 => [5 => 'foo', 12 => 'baz']];
154+
$this->assertEquals([1 => 'hAz'], Arr::except($array, 2));
155+
$this->assertEquals([1 => 'hAz', 2 => [12 => 'baz']], Arr::except($array, 2.5));
152156
}
153157

154158
public function testExists()
@@ -947,6 +951,14 @@ public function testForget()
947951
$array = ['emails' => ['[email protected]' => ['name' => 'Joe'], 'jane@localhost' => ['name' => 'Jane']]];
948952
Arr::forget($array, ['[email protected]', 'emails.jane@localhost']);
949953
$this->assertEquals(['emails' => ['[email protected]' => ['name' => 'Joe']]], $array);
954+
955+
$array = ['name' => 'hAz', '1' => 'test', 2 => 'bAz'];
956+
Arr::forget($array, 1);
957+
$this->assertEquals(['name' => 'hAz', 2 => 'bAz'], $array);
958+
959+
$array = [2 => [1 =>'products', 3 => 'users']];
960+
Arr::forget($array, 2.3);
961+
$this->assertEquals([2 => [1 =>'products']], $array);
950962
}
951963

952964
public function testWrap()

0 commit comments

Comments
 (0)