Skip to content

Commit

Permalink
Added Arr::get(), fixes #1941
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Aug 20, 2009
1 parent f87a739 commit cda9437
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions classes/kohana/arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,28 @@ public static function range($step = 10, $max = 100)
return $array;
}

/**
* Retreive a single key from an array. If the key does not exist in the
* array, the default value will be returned instead.
*
* @param array array to extract from
* @param string key name
* @param mixed default value
* @return mixed
*/
public static function get(array $array, $key, $default = NULL)
{
return isset($array[$key]) ? $array[$key] : $default;
}

/**
* Retrieves multiple keys from an array. If the key does not exist in the
* array, the default value will be added instead (NULL by default).
* array, the default value will be added instead.
*
* @param array array to extract keys from
* @param array list of keys
* @param array list of key names
* @param mixed default value
* @return array
*/
public static function extract(array $array, array $keys, $default = NULL)
{
Expand Down

0 comments on commit cda9437

Please sign in to comment.