Files
spa-api/system/arr.php

30 lines
511 B
PHP
Raw Normal View History

<?php namespace System;
class Arr {
/**
* Get an item from an array.
*
2011-07-07 23:00:40 -05:00
* If the specified key is null, the entire array will be returned.
*
* @param array $array
2011-06-16 22:27:57 -05:00
* @param string $key
* @param mixed $default
* @return mixed
*/
2011-06-16 22:27:57 -05:00
public static function get($array, $key, $default = null)
{
if (is_null($key))
{
return $array;
}
if (array_key_exists($key, $array))
{
return $array[$key];
}
return is_callable($default) ? call_user_func($default) : $default;
}
}