Created
August 7, 2019 18:32
-
-
Save parzibyte/4e14232bdcae1c1d80383ffea613f7c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Ordenar un arreglo de cadenas en PHP, y luego invertirlo | |
@author parzibyte.me/blog | |
Nota: si quieres cambiar el orden, simplemente invierte el arreglo después de ordenarlo: | |
https://parzibyte.me/blog/2018/10/15/invertir-arreglo-php/ | |
*/ | |
# El arreglo que tiene cadenas desordenadas; en este caso frutas | |
$frutas = ["Pera", "Manzana", "Sandía", "Limón", "Mango", "Melón", "Melocotón"]; | |
echo "El arreglo desordenado:\n"; | |
print_r($frutas); | |
#Lo ordenamos tomando en cuenta que son cadenas | |
sort($frutas, SORT_STRING); | |
# Ahora lo invertimos: | |
$frutas = array_reverse($frutas); | |
echo "El arreglo después de haber sido ordenado e invertido:\n"; | |
print_r($frutas); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment