Move an array element to a new index in PHP

后端 未结 9 1853
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 04:47

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

9条回答
  •  眼角桃花
    2020-12-03 05:08

    You need to create an auxiliary variable.

    moveElement($a, $i,$j)
      {
      $k=$a[$i];
      $a[$i]=$a[$j];
      $a[$j]=$k;
      return $a;
      }
    

提交回复
热议问题