Ejemplo n.º 1
0
 /**
  * Get the values of a given key.
  *
  * @param  string  $value
  * @param  string|null  $key
  * @return static
  */
 public function pluck($value, $key = null)
 {
     return new static(Arr::pluck($this->items, $value, $key));
 }
Ejemplo n.º 2
0
 /**
  * Get an item from an array or object using "dot" notation.
  *
  * @param  mixed   $target
  * @param  string|array  $key
  * @param  mixed   $default
  * @return mixed
  */
 function data_get($target, $key, $default = null)
 {
     if (is_null($key)) {
         return $target;
     }
     $key = is_array($key) ? $key : explode('.', $key);
     while (($segment = array_shift($key)) !== null) {
         if ($segment === '*') {
             if (!is_array($target) && !$target instanceof ArrayAccess) {
                 return value($default);
             }
             $result = Arr::pluck($target, $key);
             return in_array('*', $key) ? Arr::collapse($result) : $result;
         }
         if (is_array($target)) {
             if (!array_key_exists($segment, $target)) {
                 return value($default);
             }
             $target = $target[$segment];
         } elseif ($target instanceof ArrayAccess) {
             if (!isset($target[$segment])) {
                 return value($default);
             }
             $target = $target[$segment];
         } elseif (is_object($target)) {
             if (!isset($target->{$segment})) {
                 return value($default);
             }
             $target = $target->{$segment};
         } else {
             return value($default);
         }
     }
     return $target;
 }