We're a place where coders share, stay up-to-date and grow their careers.
Here is the simple solution in PHP:
PHP
function wave_sort(&$array) { sort($array); for ($index=0; $index<count($array)-1; $index+=2) { $tmp = $array[$index]; $array[$index] = $array[$index+1]; $array[$index+1] = $tmp; } }
Here is the simple solution in
PHP
: