Skip to content

Commit 5c6faa4

Browse files
committed
Update randomElements to return random number of elements when no count is provided
1 parent 029142a commit 5c6faa4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/formatters/numbers-and-strings.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ echo $faker->randomLetter();
9292

9393
## `randomElements`
9494

95-
Returns `$count` amount of random element from the given array, traversable, or enum. By default, the `$count` parameter is set to 1.
95+
Returns `$count` amount of random element from the given array, traversable, or enum. By default, the `$count` parameter is set to 1, when `null` a random number of elements is returned.
9696

9797
```php
9898
echo $faker->randomElements(['a', 'b', 'c', 'd', 'e']);
@@ -116,6 +116,10 @@ echo $faker->randomElements(Bar::class);
116116

117117
// ['c']
118118

119+
echo $faker->randomElements(Bar::class, null);
120+
121+
// ['c', 'a']
122+
119123
echo $faker->randomElements(['a', 'b', 'c', 'd', 'e'], 3);
120124

121125
// ['a', 'd', 'e']

0 commit comments

Comments
 (0)