random

Definition

1
Arr::random(array $array, int $count = 1): mixed
Copied!

Description

Get random array value(s)

Examples

1
$array = [
2
'a' => 1,
3
'b' => 2,
4
'c' => 3,
5
'd' => 4,
6
'e' => 5
7
];
8
9
Arr::random($array) -> 5
10
Arr::random($array) -> 1
11
Arr::random($array) -> 3
12
Arr::random($array) -> 2
13
14
Arr::random($array, 2) -> ['d' => 4, 'a' => 1]
15
Arr::random($array, 2) -> ['b' => 2, 'e' => 5]
16
Arr::random($array, 2) -> ['c' => 3, 'b' => 2]
Copied!
Last modified 2yr ago
Copy link