public function filter(&$array)
    {
        $current = &$array;

        $keys = array_keys($this->keyParts);
        $lastElement = end($keys);

        /**
         * This code is ugly and complicated because PHP has no way of unsetting
         * arbitrary depths inside arrays.
         *
         * The intended functionality is if you create a filter like:
         * 'form[subform][id]' then $_POST['form']['subform']['id'] will be
         * unset. This format was chosen because it's also how you would
         * represent that structure inside a form element name in your markup.
         *
         * It all works by keeping a reference to the current depth of the array,
         * iterating over key_parts (see splitKeyName), checking if the iterated
         * value exists as a key of the current reference and then setting the
         * current reference to be that key. If it's the last element of the
         * iteration then this value needs to be filtered and is removed.
         */
        foreach ($this->keyParts as $index => $keyPart) {
            if (!isset($current[$keyPart])) {
                break;
            }

            if ($index == $lastElement) {
                unset($current[$keyPart]);
                break;
            }

            $current = &$current[$keyPart];
        }
    }