I have an array of range type values 257-1024, 1-256, 1025-2056. All these values are dynamically generated and positioned randomed. Before making an output I have to sort them in a numeric ASC order. Using sort or natsort function is giving the output as 1-256,1025-2056, 257-1024 as php recognise it as string. Is there a built in function with which this can be sorted/arranged in numeric range order i.e 1-256, 257-1024, 1025-2056
2 Answers
You can use natsort() function here.
$array = array("257-1024", "1-256", "1025-2056");
$a = natsort($array);
echo "<pre>";
print_r($array);
echo "</pre>";
Output:
Array
(
[1] => 1-256
[0] => 257-1024
[2] => 1025-2056
)
Hope this helps.