Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active May 17, 2021 00:35
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 parzibyte/d8970218510cc34959933f763eb2f57b to your computer and use it in GitHub Desktop.
Save parzibyte/d8970218510cc34959933f763eb2f57b to your computer and use it in GitHub Desktop.
<?php
// https://parzibyte.me/blog
function burbuja(&$arreglo)
{
$longitud = count($arreglo);
for ($i = 0; $i < $longitud; $i++) {
for ($j = 0; $j < $longitud - 1; $j++) {
if ($arreglo[$j] < $arreglo[$j + 1]) {
$temporal = $arreglo[$j];
$arreglo[$j] = $arreglo[$j + 1];
$arreglo[$j + 1] = $temporal;
}
}
}
}
$miArreglo = ["Marijo", "Luis", "Aloy", "Zelda", "Link", "Chris", "Claire", "Leon"];
echo "Antes de ordenar: ";
print_r($miArreglo);
# Lo ordenamos
burbuja($miArreglo);
echo "Después de ordenar: ";
print_r($miArreglo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment