public function moveElement($from, $to): self
    {
        $array = $this->getArray();

        if (\is_int($from)) {
            $tmp = \array_splice($array, $from, 1);
            \array_splice($array, (int) $to, 0, $tmp);
            $output = $array;
        } elseif (\is_string($from)) {
            $indexToMove = \array_search($from, \array_keys($array), true);
            $itemToMove = $array[$from];
            if ($indexToMove !== false) {
                \array_splice($array, $indexToMove, 1);
            }
            $i = 0;
            $output = [];
            foreach ($array as $key => $item) {
                if ($i === $to) {
                    $output[$from] = $itemToMove;
                }
                $output[$key] = $item;
                ++$i;
            }
        } else {
            $output = [];
        }

        return static::create(
            $output,
            $this->iteratorClass,
            false
        );
    }
public function moveElement($from, $to): self
    {
        $array = $this->getArray();

        if (\is_int($from)) {
            $tmp = \array_splice($array, $from, 1);
            \array_splice($array, (int) $to, 0, $tmp);
            $output = $array;
        } elseif (\is_string($from)) {
            $indexToMove = \array_search($from, \array_keys($array), true);
            $itemToMove = $array[$from];
            if ($indexToMove !== false) {
                \array_splice($array, $indexToMove, 1);
            }
            $i = 0;
            $output = [];
            foreach ($array as $key => $item) {
                if ($i === $to) {
                    $output[$from] = $itemToMove;
                }
                $output[$key] = $item;
                ++$i;
            }
        } else {
            $output = [];
        }

        return static::create(
            $output,
            $this->iteratorClass,
            false
        );
    }
public function moveElement ( $ from , $ to ) : self { $ array = $ this -> getArray ( ) ; if ( \ is_int ( $ from ) ) { $ tmp = \ array_splice ( $ array , $ from , 1 ) ; \ array_splice ( $ array , ( int ) $ to , 0 , $ tmp ) ; $ output = $ array ; } elseif ( \ is_string ( $ from ) ) { $ indexToMove = \ array_search ( $ from , \ array_keys ( $ array ) , true ) ; $ itemToMove = $ array [ $ from ] ; if ( $ indexToMove !== false ) { \ array_splice ( $ array , $ indexToMove , 1 ) ; } $ i = 0 ; $ output = [ ] ; foreach ( $ array as $ key => $ item ) { if ( $ i === $ to ) { $ output [ $ from ] = $ itemToMove ; } $ output [ $ key ] = $ item ; ++ $ i ; } } else { $ output = [ ] ; } return static :: create ( $ output , $ this -> iteratorClass , false ) ; }
Move an array element to a new index.

cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php

@param int|string $from
@param int        $to

@return static
<p>(Immutable)</p>
Move an array element to a new index .