$ar[$q]) { $tmp = $ar[$p]; $ar[$p] = $ar[$q]; $ar[$q] = $tmp; } } $p++; $q--; } } $result = ""; foreach ($ar as $key => $value) { $result = $result." ".$value; } echo trim($result).PHP_EOL; return;