Skip to content

Instantly share code, notes, and snippets.

@mouradev
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mouradev/0b95f0f0340c7ceceea5 to your computer and use it in GitHub Desktop.
Save mouradev/0b95f0f0340c7ceceea5 to your computer and use it in GitHub Desktop.
<?php
$array = array(0,7,9,4,5,2,6,1,3);
$troca = true;
$tamanho = count($array);
$temp;
while($troca) {
$troca = false;
for($i = 0; $i <= ($tamanho - 2); $i++) {
if($array[$i] < $array[$i + 1]) {
$temp = $array[$i];
$array[$i] = $array[$i+1];
$array[$i+1] = $temp;
$troca = true;
}
}
}
echo '<p>crescente</p>';
for ($g = $tamanho -1; $g >= 0; $g--) {
echo $array[$g];
}
echo '<p>decrescente</p>';
for($j = 0; $j < count($array); $j++) {
echo $array[$j];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment