More WIP on Arr functions
This commit is contained in:
56
src/Arr.php
56
src/Arr.php
@@ -103,6 +103,62 @@ class Arr
|
||||
return array_count_values(...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares `$array` against one or more other arrays and returns the values in `$array` that are not present in any
|
||||
* of the other arrays.
|
||||
*
|
||||
* @param array ...$arrays The arrays against which the comparison should be made
|
||||
* @return callable<array, array> A function that calls `array_diff` with the given array.
|
||||
* @see https://www.php.net/manual/en/function.array-diff.php array_diff Documentation
|
||||
*/
|
||||
public static function diff(array ...$arrays): callable
|
||||
{
|
||||
return fn (array $array) => array_diff($array, ...$arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares `$array` against `$arrays` and returns the difference. Unlike `Arr::diff()`, the array keys are also
|
||||
* used in the comparison.
|
||||
*
|
||||
* @param array ...$arrays The arrays against which the comparison should be made
|
||||
* @return callable<array, array> A function that calls `array_diff_assoc` with the given array.
|
||||
* @see https://www.php.net/manual/en/function.array-diff-assoc.php array_diff_assoc Documentation
|
||||
*/
|
||||
public static function diffAssoc(array ...$arrays): callable
|
||||
{
|
||||
return fn (array $array) => array_diff_assoc($array, ...$arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the keys from `$array` against the keys from `$arrays` and returns the difference. This function is like
|
||||
* `Arr::diff()`, except the comparison is done on the keys instead of the values.
|
||||
*
|
||||
* @param array ...$arrays The arrays against which the comparison should be made
|
||||
* @return callable<array, array> A function that calls `array_diff_key` with the given array.
|
||||
* @see https://www.php.net/manual/en/function.array-diff-key.php array_diff_key Documentation
|
||||
*/
|
||||
public static function diffKey(array ...$arrays): callable
|
||||
{
|
||||
return fn (array $array) => array_diff_key($array, ...$arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares `$array` against `$arrays` and returns the difference. Unlike `Arr::diff()`, the array keys are also
|
||||
* used in the comparison. Unlike `Arr::diffAssoc()`, a user supplied callback function is used for the indices
|
||||
* comparison, not internal function.
|
||||
*
|
||||
* @param callable<mixed, mixed, int> $keyCompareFunc The comparison function must return an integer less than,
|
||||
* equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or
|
||||
* greater than the second.
|
||||
* @param array ...$arrays The arrays against which the comparison should be made
|
||||
* @return callable<array, array> A function that calls `array_diff_assoc` with the given array.
|
||||
* @see https://www.php.net/manual/en/function.array-diff-assoc.php array_diff_assoc Documentation
|
||||
*/
|
||||
public static function diffUAssoc(callable $keyCompareFunc, array ...$arrays): callable
|
||||
{
|
||||
return fn (array $array) => array_diff_uassoc($array, $arrays, $keyCompareFunc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform each element of an array to a different element (optionally merging other mapped arrays).
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user