Upgrade to 3.9.3

This commit is contained in:
Bastian Allgeier
2023-03-30 15:17:37 +02:00
parent 20e971adb4
commit cd495f054e
47 changed files with 3386 additions and 2384 deletions

View File

@@ -48,6 +48,17 @@ class A
return $array;
}
/**
* Counts the number of elements in an array
*
* @param array $array
* @return int
*/
public static function count(array $array): int
{
return count($array);
}
/**
* Gets an element of an array by key
*
@@ -150,6 +161,19 @@ class A
return $default;
}
/**
* Checks if array has a value
*
* @param array $array
* @param mixed $value
* @param bool $strict
* @return bool
*/
public static function has(array $array, $value, bool $strict = false): bool
{
return in_array($value, $array, $strict);
}
/**
* Joins the elements of an array to a string
*/
@@ -309,6 +333,19 @@ class A
return $prepend + $array;
}
/**
* Reduce an array to a single value
*
* @param array $array
* @param callable $callback
* @param mixed $initial
* @return mixed
*/
public static function reduce(array $array, callable $callback, $initial = null): mixed
{
return array_reduce($array, $callback, $initial);
}
/**
* Shuffles an array and keeps the keys
*
@@ -345,6 +382,36 @@ class A
return $new;
}
/**
* Returns a slice of an array
*
* @param array $array
* @param int $offset
* @param int|null $length
* @param bool $preserveKeys
* @return array
*/
public static function slice(
array $array,
int $offset,
int $length = null,
bool $preserveKeys = false
): array {
return array_slice($array, $offset, $length, $preserveKeys);
}
/**
* Sums an array
*
* @param array $array
* @return int|float
*/
public static function sum(array $array): int|float
{
return array_sum($array);
}
/**
* Returns the first element of an array
*