Ouzo\Utilities\Arrays::removeNestedKey PHP Метод

removeNestedKey() публичный статический Метод

Example: $array = array('1' => array('2' => array('3' => 'value'))); Arrays::removeNestedKey($array, array('1', '2')); Result: Array ( [1] => Array ( ) )
public static removeNestedKey ( array &$array, array $keys, boolean $removeEmptyParents = false )
$array array
$keys array
$removeEmptyParents boolean
    public static function removeNestedKey(array &$array, array $keys, $removeEmptyParents = false)
    {
        $key = array_shift($keys);
        if (count($keys) == 0) {
            unset($array[$key]);
        } elseif (isset($array[$key])) {
            self::removeNestedKey($array[$key], $keys, $removeEmptyParents);
            if ($removeEmptyParents && empty($array[$key])) {
                unset($array[$key]);
            }
        }
    }

Usage Example

Пример #1
0
 public function remove($keys)
 {
     if (!isset($_SESSION)) {
         return null;
     }
     Arrays::removeNestedKey($_SESSION, Arrays::toArray($keys));
 }
All Usage Examples Of Ouzo\Utilities\Arrays::removeNestedKey