Collection > the getByIndex() method > returns element with given index

This commit is contained in:
Meritoo
2019-03-16 19:58:02 +01:00
parent 9f6af6b6a4
commit eade6a25ad
2 changed files with 95 additions and 0 deletions

View File

@@ -188,6 +188,21 @@ trait MainTrait
return Arrays::getLastElement($this->elements);
}
/**
* Returns element with given index
*
* @param mixed $index Index / key of the element
* @return mixed|null
*/
public function getByIndex($index)
{
if (isset($this->elements[$index])) {
return $this->elements[$index];
}
return null;
}
/**
* Returns representation of object as array
*