Skip to content

Commit

Permalink
added exclude method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerstens Maxim committed Aug 9, 2013
1 parent 4ce311f commit 30e7a4f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions classes/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,39 @@ public static function partition( array $array, $size = 2 )

return $partition;
}

/**
* Exclude certain keys from the provided array.
*
* If $format is true the return will be formatted to ['free' => [], 'excluded' => []]
*
* @param array $array
* @param array $keys Keys to exclude from the provided array
* @param bool $format Do we keep excluded keys?
* @return array
*/
public static function exclude($array, $keys, $format=false)
{
$list = ($format) ? array('free' => array(), 'excluded' => array()) : array();

foreach($array as $key => $value) {
if ( ! in_array($key, $keys))
{
if($format)
{
$list['free'][$key] = $value;
}
else
{
$list[$key] = $value;
}
}
else if ($format)
{
$list['excluded'][$key] = $value;
}
}

return $list;
}
}

0 comments on commit 30e7a4f

Please sign in to comment.