## EX.NO: 10
Apply any two PHP sort functions each on an indexed array and an associative array
### Aim
To apply any two PHP sort functions, each on an indexed array and an associative array.
### Algorithm
1. Create a PHP file to define an indexed array and an associative array.
2. Apply sorting functions such as `sort()` and `rsort()` for indexed arrays, and `asort()` and `ksort()` for associative arrays.
3. Display the original and sorted arrays to observe the changes.
4. Save and execute the PHP file in XAMPP to verify the result.
## Program
### `sort.php`
PHP
```
PHP Sort Functions
Apply PHP Sort Functions
25,
"Jane" => 30,
"Peter" => 22,
"Tom" => 35
);
// Display the original indexed array
echo "Original Indexed Array:
";
print_r($indexedArray);
// Applying sort() on indexed array
// Sorts the array in ascending order
sort($indexedArray);
echo "Indexed Array after sort() (ascending):
";
print_r($indexedArray);
echo "
";
// Display the original associative array
echo "Original Associative Array:
";
print_r($associativeArray);
// Applying asort() on associative array
// Sorts the array by values
asort($associativeArray);
echo "Associative Array after asort() (sorted by values):
";
print_r($associativeArray);
echo "
";
// Applying ksort() on associative array
// Sorts the array by keys
ksort($associativeArray);
echo "Associative Array after ksort() (sorted by keys):
";
print_r($associativeArray);
?>
```
### Output
The original indexed array is displayed first. After applying `sort()`, the indexed array is displayed in ascending order.
The original associative array is then displayed. After applying `asort()`, the array is sorted according to its values. Finally, `ksort()` sorts the associative array according to its keys.
### Result
Thus, the PHP program to apply two sort functions on an indexed array and an associative array is executed successfully, and the output is verified.