I\'m looking for a simple function to move an array element to a new position in the array and resequence the indexes so that there are no gaps in the sequence. It doesnt ne
May be I'm wrong but shouldn't it be easier just to make a copy of the array and then replace the values?
function swap($input, $a, $b){ $output = $input; $output[$a] = $input[$b]; $output[$b] = $input[$a]; return $output; } $array = ['a', 'c', 'b']; $array = swap($array, 1, 2);