Moving key in array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Moving key in array

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

array_splice can do such things.
Post Reply