I cannot find an effective solution on rearranging/swapping an array item by its value by shifting by - 1 or + 1. I\'m making an order on tables, i
- 1
+ 1
Shifting up (assuming you've checked that the item is not already the first one):
$item = $array[ $index ]; $array[ $index ] = $array[ $index - 1 ]; $array[ $index - 1 ] = $item;
Shifting down:
$item = $array[ $index ]; $array[ $index ] = $array[ $index + 1 ]; $array[ $index + 1 ] = $item;