sort & ksort
sort
sort
It sort an elements of a given array.
Syntax:
void sort ( array array [, int sort_flags])
- This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.
ksort
ksort
It Sort an array by key.
Syntax:
int ksort ( array array [, int sort_flags])
It sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays.
Example:
$input1 = array (”lemon”, “orange”, “banana”, “apple”);
$input2 = array (”d”=>”lemon”, “a”=>”orange”, “b”=>”banana”, “c”=>”apple”);
sort ($input1);
ksort ($input2);
print_r($input1);
print_r($input2);
The result in $input1 is
Array
(
[0] => apple
[1] => banana
[2] => lemon
[3] => orange
)
The result in $input2 is
Array
(
[a] => orange
[b] => banana
[c] => apple
[d] => lemon
)
