Jump to content

move array item to bottom and move rest up


glenelkins

Recommended Posts

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

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
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.