Minwork Array
  • Minwork Array
  • Common methods
    • has
    • get → getNestedElement
    • set → setNestedElement
    • remove
    • clone
    • getKeysArray
  • Object oriented methods
    • General information
  • Traversing array
    • Finding
    • Iterating
  • Manipulating array
    • Mapping
    • Filtering
    • Grouping
    • Sorting
    • Computations
    • Flattening
  • Validating array
    • check
    • isEmpty
    • isNested
    • isArrayOfArrays
    • isAssoc
    • isUnique
    • isNumeric
    • hasKeys
  • Utility methods
    • pack
    • unpack
    • createMulti
    • forceArray
    • getDepth
    • random
    • shuffle
    • nth
    • getFirstKey
    • getLastKey
    • getFirstValue
    • getLastValue
Powered by GitBook
On this page

Was this helpful?

  1. Utility methods

random

Definition

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

Description

Get random array value(s)

Examples

$array = [
    'a' => 1, 
    'b' => 2, 
    'c' => 3, 
    'd' => 4, 
    'e' => 5
];

Arr::random($array) -> 5
Arr::random($array) -> 1
Arr::random($array) -> 3
Arr::random($array) -> 2

Arr::random($array, 2) -> ['d' => 4, 'a' => 1]
Arr::random($array, 2) -> ['b' => 2, 'e' => 5]
Arr::random($array, 2) -> ['c' => 3, 'b' => 2]
PreviousgetDepthNextshuffle

Last updated 5 years ago

Was this helpful?