mirror of
https://github.com/getformwork/formwork.git
synced 2025-03-14 19:19:48 +01:00
Add Arr::nth()
and Arr::duplicates()
This commit is contained in:
parent
e0436303fa
commit
42e47decc5
@ -96,6 +96,15 @@ class Arr
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array value at the given index,
|
||||
* negative indices are not allowed, use `Arr:at()` instead
|
||||
*/
|
||||
public static function nth(array $array, int $index)
|
||||
{
|
||||
return array_values($array)[$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array value at the given index,
|
||||
* negative indices are allowed and start from the end
|
||||
@ -123,6 +132,14 @@ class Arr
|
||||
return $key !== false ? $key : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the duplicate elements of the array
|
||||
*/
|
||||
public static function duplicates(array $array): array
|
||||
{
|
||||
return array_diff_key($array, array_unique($array));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively append elements from the second array that are missing in the first
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user