Page 1 of 1

Moving elements of an array?

Posted: Mon Sep 26, 2005 7:22 pm
by cheerio
how do i move an element of an array to a different location? for example,

i have an array array(1,2,3,4,5,6)
and i want to move the 3 after the for so it ends up as array(1,2,4,3,5,6)

how is this done???

Posted: Mon Sep 26, 2005 7:37 pm
by feyd
array_splice()

You'll need two of them. One to extract, one to insert.

Posted: Mon Sep 26, 2005 8:14 pm
by harrisonad
simple manual solution

Code: Select all

$x = $aray[4];
$aray[4] = $aray[3];
$aray[3] = $x;

Posted: Fri Sep 30, 2005 9:21 pm
by cheerio
thanks guys :)