Browse Source

Added support for closures as Arr::get default parameter.

Taylor Otwell 13 years ago
parent
commit
65ffe0b610
1 changed files with 7 additions and 2 deletions
  1. 7 2
      system/arr.php

+ 7 - 2
system/arr.php

@@ -7,7 +7,7 @@ class Arr {
 	 *
 	 * @param  array   $array
 	 * @param  string  $key
-	 * @param  array   $default
+	 * @param  mixed   $default
 	 * @return mixed
 	 */
 	public static function get($array, $key, $default = null)
@@ -17,7 +17,12 @@ class Arr {
 			return $array;
 		}
 
-		return (array_key_exists($key, $array)) ? $array[$key] : $default;
+		if (array_key_exists($key, $array))
+		{
+			return $array[$key];
+		}
+
+		return is_callable($default) ? call_user_func($default) : $default;
 	}
 
 }