Page 1 of 1

Moving key in array

Posted: Tue Feb 08, 2005 12:59 pm
by Pineriver
Might there be a function for this... I have tried but I cant find anything
Would like key "a" moved to "c" but not replacing

Code: Select all

$foo= array(a,b,c,d);

$movefrom =0; // the pos of the key in $foo which is "a"
$moveto = 2; // where "a" should be moved to

movekey($movefrom,$moveto);
$foo would now be

Array
(
[0] => b;
[1] => c;
[2] => a;
[3] => d;
)
Thanks in advance

Posted: Tue Feb 08, 2005 3:06 pm
by feyd
array_splice can do such things.