First of all: do you really need an index as a string? You always use "test"? Is this just an example?
If you don't need it, simply do this:
One dimensional array
<?php
$result = array('21:00', '11:00', '19:00', '04:00', '01:00', '13:45', '02:45', '00:00');
sort($result, SORT_STRING);
var_dump($result);
?>
Output:
array(8) { [0]=> string(5) "00:00" [1]=> string(5) "01:00" [2]=> string(5) "02:45" [3]=> string(5) "04:00" [4]=> string(5) "11:00" [5]=> string(5) "13:45" [6]=> string(5) "19:00" [7]=> string(5) "21:00" }
Using a multi-dimensional array
(based on the code you provided in the comment)
This sample does what you want but it's not the way I would do it. I recommend using a class instead a second array. This is much cleaner and uses a more advanced coding style. As far as I see from your example your are creating the arrays manually so it does not result in a big change.
<?php
// Define a custom compare function that uses the inner array of your
// multi-dimensional array.
function compareMealTime($a, $b)
{
return strcmp($a['MealTime'], $b['MealTime']);
}
$result = array();
$result[0] = array('blabla' => 123123, 'MealTime' => '21:00');
$result[1] = array('assd' => 123123, 'MealTime' => '02:00');
$result[2] = array('blabsdsddla' => 123123, 'MealTime' => '00:00');
$result[3] = array('bladddbla' => 123123, 'MealTime' => '04:00');
uasort($result, 'compareMealTime');
var_dump($result);
?>
Output:
array(4) { [2]=> array(2) { ["blabsdsddla"]=> int(123123) ["MealTime"]=> string(5) "00:00" } [1]=> array(2) { ["assd"]=> int(123123) ["MealTime"]=> string(5) "02:00" } [3]=> array(2) { ["bladddbla"]=> int(123123) ["MealTime"]=> string(5) "04:00" } [0]=> array(2) { ["blabla"]=> int(123123) ["MealTime"]=> string(5) "21:00" } }
Otherwise you can use sort(), asort() as Liam Allan suggested or uasort().
Check Sorting Arrays for a comparison of these functions to find out the one that best fits your needs.