Kraken\Util\Support\ArraySupport::remove PHP Method

remove() public static method

Remove the value stored under given key from the array with dot notation support.
public static remove ( &$array, string $key ) : boolean
$key string
return boolean
    public static function remove(&$array, $key)
    {
        $key = static::normalizeKey($key);
        if ($key === null || $key === '') {
            return $array = [];
        }
        $keys = explode('.', $key);
        $last = array_pop($keys);
        $currentElement =& $array;
        foreach ($keys as $currentKey) {
            if (!array_key_exists($currentKey, $currentElement) || !is_array($currentElement[$currentKey])) {
                $currentElement[$currentKey] = [];
            }
            $currentElement =& $currentElement[$currentKey];
        }
        unset($currentElement[$last]);
        return $array;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @override
  * @inheritDoc
  */
 public function remove($key)
 {
     return ArraySupport::remove($this->config, $key);
 }