Habari\SuperGlobal::merge PHP Метод

merge() публичный Метод

Merges the contents of one or more arrays or ArrayObjects with this SuperGlobal
public merge ( ) : SuperGlobal
Результат SuperGlobal The merged array
    public function merge()
    {
        $args = func_get_args();
        $cp = $this->get_array_copy_raw();
        foreach ($args as $ary) {
            if (is_array($ary)) {
                foreach ($ary as $key => $value) {
                    if (is_numeric($key)) {
                        $cp[] = $value;
                    } else {
                        $cp[$key] = $value;
                    }
                }
            } elseif ($ary instanceof SuperGlobal) {
                // loop to get raw data.
                while ($ary->valid()) {
                    if (is_numeric($ary->key())) {
                        $cp[] = $ary->raw($ary->key());
                    } else {
                        $cp[$ary->key()] = $ary->raw($ary->key());
                    }
                    $ary->next();
                }
            } elseif ($ary instanceof \ArrayObject || $ary instanceof \ArrayIterator) {
                $arycp = $ary->getArrayCopy();
                // Don't trigger offsetGet for ArrayObject
                foreach ($arycp as $key => $value) {
                    if (is_numeric($key)) {
                        $cp[] = $value;
                    } else {
                        $cp[$key] = $value;
                    }
                }
            } else {
                $cp[] = $ary;
            }
        }
        return new SuperGlobal($cp);
    }