Here are a couple of routines to swap the order of two elements in an array
<?php
function array_swap_forward($arr,$elem)
{
$ndx = array_search($elem,$arr) - 1;
$b4 = array_slice($arr,0,$ndx);
$mid = array_reverse(array_slice($arr,$ndx,2));
$after = array_slice($arr,$ndx + 2);
return array_merge($b4,$mid,$after);
}
function array_swap_back($arr,$elem)
{
$ndx = array_search($elem,$arr);
$b4 = array_slice($arr,0,$ndx);
$mid = array_reverse(array_slice($arr,$ndx,2));
$after = array_slice($arr,$ndx + 2);
return array_merge($b4,$mid,$after);
}
$arr =array('a','b','c','d','e','f');
print_r(array_swap_forward($arr,'c'));
echo '<br>';
print_r(array_swap_back($arr,'c'));
?>