Skip to content

Commit

Permalink
improve get element
Browse files Browse the repository at this point in the history
  • Loading branch information
ad3n committed Jul 20, 2019
1 parent 0b0fef5 commit e1d21b9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ public function add($value, $key = null)
*
* @param mixed $key
*
* @return mixed|null
* @return int|string|null|Collection
*/
public function get($key)
{
return $this->elements[$key] ?? null;
if (!array_key_exists($key, $this->elements)) {
return null;
}

if (!is_array($this->elements[$key])) {
return $this->elements[$key];
}

return self::collect($this->elements[$key]);
}

/**
Expand Down

0 comments on commit e1d21b9

Please sign in to comment.