示例#1
0
 /**
  * Get an attribute from the container.
  *
  * @param  string $key
  * @param  mixed $default
  *
  * @return mixed
  */
 public function get($key, $default = null)
 {
     if (array_key_exists($key, $this->attributes)) {
         return $this->attributes[$key];
     }
     return Misc::value($default);
 }
示例#2
0
 /**
  * Get an item from the collection by key.
  *
  * @param  mixed $key
  * @param  mixed $default
  *
  * @return mixed
  */
 public function get($key, $default = null)
 {
     if ($this->offsetExists($key)) {
         return $this->items[$key];
     }
     return Misc::value($default);
 }
示例#3
0
文件: Arr.php 项目: th3fallen/support
 /**
  * Get an item from an array using "dot" notation.
  *
  * @param  \ArrayAccess|array $array
  * @param  string $key
  * @param  mixed $default
  *
  * @return mixed
  */
 public static function get($array, $key, $default = null)
 {
     if (!static::accessible($array)) {
         return Misc::value($default);
     }
     if (is_null($key)) {
         return $array;
     }
     if (static::exists($array, $key)) {
         return $array[$key];
     }
     foreach (explode('.', $key) as $segment) {
         if (static::accessible($array) && static::exists($array, $segment)) {
             $array = $array[$segment];
         } else {
             return Misc::value($default);
         }
     }
     return $array;
 }