Get last element of array.

@param mixed[] $data
@param string $key Get key from element if array. Default null.
@return mixed
355381
public static function last(array $data, ?string $key = null)
    {
        if (count($data) === 0) {
            return null;
        }
        $element = end($data);
        if ($key !== null && is_array($element) && isset($element[$key])) {
            return $element[$key];
        }
        return $element;
    }
1139781
public function getValue($data, $keys, $default = null)
    {
        if ($this->isKeysEmpty($keys)) {
            return $data;
        }
        if (!is_array($keys)) {
            $keys = [$keys];
        }

        $accessor = new Accessor($data);
        foreach ($keys as $key) {
            if ($accessor->to($key) === false) {
                return $default;
            }
        }

        return $accessor->getCurrent();
    }
36710
public function setData($data, $key = null)
	{
		if (is_array($data) && $key === null) {
			$this->data = $data;

			return $this;
		}

		if ($key === null)
			$key = 'data';

		$this->data[$key] = $data;

		return $this;
	}
1143959
public function getSafeArray(string $key, array & $data, string $default = null)
    {
        $value = $this->getFromArray($key, $data, $default);

        return \htmlspecialchars($value);
    }
478317
public static function getValueByKey($data, $key = null, $default = null)
    {
        if (!isset($key) || empty($key)) {
            return $data;
        }

        if (is_array($key)) {
            $keys = $key;
        } else {
            $keys = explode('.', $key);
        }

        $item = $data;
        foreach ($keys as $keyName) {
            if (is_array($item)) {
                if (isset($item[$keyName])) {
                    $item = $item[$keyName];
                } else {
                    return $default;
                }
            } else if (is_object($item)) {
                if (isset($item->$keyName)) {
                    $item = $item->$keyName;
                } else {
                    return $default;
                }
            }

        }

        return $item;
    }
921278
public function get($key = null){
        if(null === $key){
            return array_merge($this->_data, $this->_dirty);
        }
        else{
            if(isset($this->_dirty[$key])){
                return $this->_dirty[$key];
            }
            elseif(isset($this->_data[$key])){
                return $this->_data[$key];
            }
            else{
                return null;
            }
        }
    }
939575
public function getData($key = null)
    {
        if (null === $key) {
            return $this->data;
        }
        
        $return = $this->data;
        foreach (explode('.', $key) as $subKey) {
            if (isset($return[$subKey])) {
                $return = $return[$subKey];
            } else {
                return null;
            }
        }
        return $return;
    }
1056777
public static function get($array, string $key, $default = null)
    {
        if (! Assert::array($array)) {
            return $default;
        }

        $key = trim($key);

        if ($key === '') {
            return $array;
        }

        if (static::exists($array, $key)) {
            return $array[$key];
        }

        foreach (explode('.', $key) as $segment) {
            if (Assert::array($array) && static::exists($array, $segment)) {
                $array = $array[$segment];
            } else {
                return $default;
            }
        }

        return $array;
    }
422863
public function get($key)
    {
        if (empty($this->data[$key]) === true) {
            return null;
        }

        return $this->data[$key];
    }
510589
public static function get(array $data, string $key, $defaultValue = null)
    {
        $data = self::dataByPath($data, $key);
        if ($data === null) {
            $data = $defaultValue;
        }
        return $data;
    }
63045
public function save(array $data, $key = null)
    {
        if (is_null($key)) {
            $key = $this->defaultKey;
        }

        return $this->driver->save($data, $this->getKey($key));
    }
490596
private static function recursiveGetFromKey($data, $key, $default)
    {
        if (empty($key)) {
            return $data;
        } else {
            $currentKey = array_shift($key);
            return isset($data[$currentKey]) ? self::recursiveGetFromKey($data[$currentKey], $key, $default) : $default;
        }
    }
55375
protected function getRegularValues($data, $key, array $keys) {
        $values = [];

        if (count($keys) === 0) {
            $values[$key] = $this->propertyReader->getProperty($data, $key);
        }

        if (count($keys) > 0) {
            $value = $this->propertyReader->getProperty($data, $key);
            $nestedValues = $this->getValues($value, $keys);

            foreach ($nestedValues as $nestedKey => $nestedValue) {
                $values[$this->buildKey($key, $nestedKey)] = $nestedValue;
            }
        }

        return $values;
    }
1074093
protected function extractValue($key, $data)
    {
        $real_varname = mb_substr($key, 1, mb_strlen($key) - 2);

        $key = $this->cleanKey($key);

        if (isset($data[$key])) {
            return $data[$key];
        }

        if (!$this->isNestedKey($key)) {
            return null;
        }

        $segments = explode($this->nestingSeparator, $key);

        $last = count($segments) - 1;
        $varname = $segments[0];

        if (!isset($data[$varname])) {
            return null;
        }

        $node = &$data[$varname];

        //$i=1 because view varname is still inside segments
        for ($i = 1; $i <= $last; ++$i) {
            $node = @$this->getNode($node, $segments[$i]);

            if ($node === null) {
                return null;
            }

            if (is_scalar($node)) {
                if ($i == $last) {
                    return $node;
                }

                return null;
            }
        }

        return null;
    }
675100
public function lastKey()
    {
        $keys = AccessHelper::collectionKeys($this->data);

        if (empty($keys) || end($keys) === false) {
            return null;
        }

        return end($keys);
    }
243573
public function getArray($key)
    {
        try {
            $result = $this->get(self::DATA_ARRAY, $key);
            if (!settype($result, 'array')) {
                return null;
            }
        } catch (\Exception $e) {
            return null;
        }
        return $result;
    }
567076
public function indexBy(array $data, $key)
    {
        $newData = [];
        foreach ($data as $row) {
            $newData[$row[$key]] = $row;
        }

        return $newData;
    }