Rearrange array max value and min value after that second max and second min

$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
$n = count($arr);
$temp[$n];
$small=0; $large=$n-1;
$flag = true;
for ($i=0; $i<$n; $i++) { if ($flag){ $temp[$i] = $arr[$large--]; } else{ $temp[$i] = $arr[$small++]; } $flag = !$flag; } for ($i=0; $i<$n; $i++){ $arr[$i] = $temp[$i]; } print_r($arr);

Rearrange array max value and min value after that second max and second min
Show Buttons
Hide Buttons