for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* Copyright (C) 2018 Sebastian Böttger <[email protected]>
* You may use, distribute and modify this code under the
* terms of the MIT license.
*
* You should have received a copy of the MIT license with
* this file. If not, please visit: https://opensource.org/licenses/mit-license.php
*/
namespace Seboettg\Collection\NativePhp;
/**
* Trait ArrayAccessTrait
* @package Seboettg\Collection\ArrayList
trait ArrayAccessTrait
{
* Offset to retrieve
* @link http://php.net/manual/en/arrayaccess.offsetget.php
* @param mixed $offset The offset to retrieve.
* @return mixed Can return all value types.
public function offsetGet($offset)
return $this->array[$offset] ?? null;
}
* Offset to set
* @link http://php.net/manual/en/arrayaccess.offsetset.php
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
public function offsetSet($offset, $value)
$this->array[$offset] = $value;
array
* Whether a offset exists
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
* @param mixed $offset
* @return bool
public function offsetExists($offset): bool
return isset($this->array[$offset]);
* Offset to unset
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset The offset to unset.
public function offsetUnset($offset)
unset($this->array[$offset]);