There is an array:
$array[0]= '5'; $array[1]= '3'; $array[2]= '2'; $array[3]= '1'; $array[4]= '14'; How to sort its values into something like this:
$array[0]= '1'; $array[1]= '2'; $array[2]= '3'; $array[3]= '5'; $array[4]= '14'; There is an array:
$array[0]= '5'; $array[1]= '3'; $array[2]= '2'; $array[3]= '1'; $array[4]= '14'; How to sort its values into something like this:
$array[0]= '1'; $array[1]= '2'; $array[2]= '3'; $array[3]= '5'; $array[4]= '14'; In your case, the function will help
sort($array); http://php.net/manual/ru/function.sort.php
As the first argument, this function takes an array and sorts it. The new array will be written instead of the old one (here the argument is passed by reference).
Here is:
$array= array("1", "2", "3", "4"); sort($array, SORT_NATURAL | SORT_FLAG_CASE); foreach ($array as $key => $val) { echo "array[" . $key . "] = " . $val . "\n"; } Source: https://ru.stackoverflow.com/questions/536162/
All Articles