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

nth

Definition

Arr::nth(array $array, int $A = 1, int $B = 0): array

Aliases

even(array $array) -> nth($array, 2)
odd(array $array)  -> nth($array, 2, 1)

Description

Gets array elements with index matching condition $An + $B (preserving original keys)

Examples

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

Arr::nth($array, 2, 3) ->
[
    'c' => 2,
    'e' => 4,
]

Arr::nth($array, 2) === Arr::even($array) ->
[
    'a' => 0, 
    'c' => 2, 
    'e' => 4,
]

Arr::nth($array, 2, 1) === Arr::odd($array) ->
[
    'b' => 1, 
    'd' => 3,
]
PreviousshuffleNextgetFirstKey

Last updated 5 years ago

Was this helpful?