Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created August 13, 2015 11:52
Show Gist options
  • Save VictorFursa/4bb43c86b51627f7d991 to your computer and use it in GitHub Desktop.
Save VictorFursa/4bb43c86b51627f7d991 to your computer and use it in GitHub Desktop.
$array = array(100,200,300,400,500,600,700,800,1,2,3,4,5,6,7,8,9,10,2,2,2,2,2,2,2,2,2,2,2,2);
for($i = 0;$i < count($array);$i++){
if ( $i % 2) {
if (isset($array[$i - 1])) {
$buffer = $array[$i];
$array[$i] = $array[$i - 1];
$array[$i - 1] = $buffer;
}
}
}
var_dump($array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment