Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
added except fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Sep 17, 2016
1 parent 2929650 commit e2269dc
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/Arr/Arr.php
Expand Up @@ -522,7 +522,7 @@ public static function collapse(array $array): array
foreach ($array as $key => $value) {
if (is_array($value)) {
// strip any manually added '.'
if (preg_match('/\./', $key)) {
if (preg_match('/\./', (string) $key)) {
$key = substr($key, 0, -2);
}

Expand Down Expand Up @@ -1116,17 +1116,17 @@ public static function where(array $array, callable $callback): array
/**
* Return the first element in an array passing a given truth test.
*
* @param array $array
* @param callable $callback
* @param mixed $default
* @param array $array
* @param callable|null $callback
* @param mixed $default
*
* @return mixed
*/
public static function first(array $array, callable $callback, $default = null)
public static function first(array $array, callable $callback = null, $default = null)
{
if (is_null($callback)) {
if (empty($array)) {
return value($default);
return static::value($default);
}

foreach ($array as $item) {
Expand All @@ -1146,13 +1146,13 @@ public static function first(array $array, callable $callback, $default = null)
/**
* Return the last element in an array passing a given truth test.
*
* @param array $array
* @param callable $callback
* @param mixed $default
* @param array $array
* @param callable|null $callback
* @param mixed $default
*
* @return mixed
*/
public static function last(array $array, callable $callback, $default = null)
public static function last(array $array, callable $callback = null, $default = null)
{
if (is_null($callback)) {
return empty($array) ? static::value($default) : end($array);
Expand All @@ -1161,6 +1161,21 @@ public static function last(array $array, callable $callback, $default = null)
return static::first(array_reverse($array), $callback, $default);
}

/**
* Get all of the given array except for a specified array of items.
*
* @param array $array
* @param array|string $keys
*
* @return array
*/
public static function except(array $array, $keys): array
{
static::forget($array, $keys);

return $array;
}

/**
* Return the default value of the given value.
*
Expand Down

0 comments on commit e2269dc

Please sign in to comment.