glenelkins Posted April 8, 2009 Share Posted April 8, 2009 hi the title says it all really. say i have this array 1=>1 2=>8 3=>4 4=>5 5=>2 6=>7 7=>3 8=>6 How can i move arrray position 3, to position 8, and shift the rest up?? Without having to use loops, im sure there will be some functions available Quote Link to comment https://forums.phpfreaks.com/topic/153151-move-array-item-to-bottom-and-move-rest-up/ Share on other sites More sharing options...
MadTechie Posted April 8, 2009 Share Posted April 8, 2009 Maybe $tmp = array(1,8,4,5,2,7,3,6); $tmp = MoveDown($tmp, 3); fucntion MoveDown($arr, $pos) { $t = $arr[$pos]; unset($arr[$pos]); $arr[] = $arr[$pos]; return array_values($arr); //re-index //OR return $arr; //don't care about the index } Quote Link to comment https://forums.phpfreaks.com/topic/153151-move-array-item-to-bottom-and-move-rest-up/#findComment-804502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.