Created
July 31, 2019 17:29
-
-
Save parzibyte/9b204df8410cb657da1eb13adb7fed75 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 | |
$arreglo = [ | |
[ | |
"hora" => "07:00:00", | |
"fecha" => "2019-07-30", | |
"datetime" => "2019-07-30 07:00:00", | |
], | |
[ | |
"hora" => "13:15:20", | |
"fecha" => "2002-11-24", | |
"datetime" => "2002-11-24 13:15:20", | |
], | |
[ | |
"hora" => "15:27:32", | |
"fecha" => "2007-10-29", | |
"datetime" => "2007-10-29 15:27:32", | |
], | |
[ | |
"hora" => "15:27:33", | |
"fecha" => "2007-10-29", | |
"datetime" => "2007-10-29 15:27:33", | |
], | |
]; | |
echo "Arreglo antes de ordenar: "; | |
print_r($arreglo); | |
usort($arreglo, function ($a, $b) { | |
return strcmp($a["datetime"], $b["datetime"]); | |
}); | |
echo "Arreglo DESPUÉS de ordenar: "; | |
print_r($arreglo); | |
/* | |
Salida: | |
Arreglo antes de ordenar: Array | |
( | |
[0] => Array | |
( | |
[hora] => 07:00:00 | |
[fecha] => 2019-07-30 | |
[datetime] => 2019-07-30 07:00:00 | |
) | |
[1] => Array | |
( | |
[hora] => 13:15:20 | |
[fecha] => 2002-11-24 | |
[datetime] => 2002-11-24 13:15:20 | |
) | |
[2] => Array | |
( | |
[hora] => 15:27:32 | |
[fecha] => 2007-10-29 | |
[datetime] => 2007-10-29 15:27:32 | |
) | |
[3] => Array | |
( | |
[hora] => 15:27:33 | |
[fecha] => 2007-10-29 | |
[datetime] => 2007-10-29 15:27:33 | |
) | |
) | |
Arreglo DESPUÉS de ordenar: Array | |
( | |
[0] => Array | |
( | |
[hora] => 13:15:20 | |
[fecha] => 2002-11-24 | |
[datetime] => 2002-11-24 13:15:20 | |
) | |
[1] => Array | |
( | |
[hora] => 15:27:32 | |
[fecha] => 2007-10-29 | |
[datetime] => 2007-10-29 15:27:32 | |
) | |
[2] => Array | |
( | |
[hora] => 15:27:33 | |
[fecha] => 2007-10-29 | |
[datetime] => 2007-10-29 15:27:33 | |
) | |
[3] => Array | |
( | |
[hora] => 07:00:00 | |
[fecha] => 2019-07-30 | |
[datetime] => 2019-07-30 07:00:00 | |
) | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment