How can PHP arrays be effectively utilized for sorting and organizing data?

PHP arrays can be effectively utilized for sorting and organizing data by using built-in array functions like sort(), asort(), ksort(), etc. These functions allow you to sort arrays based on values or keys, in ascending or descending order. By using these functions, you can easily rearrange and organize data within an array.

// Example of sorting an array of numbers in ascending order
$numbers = [5, 2, 8, 1, 9];
sort($numbers);

// Example of sorting an associative array by values in descending order
$fruits = ['apple' => 5, 'banana' => 3, 'cherry' => 8];
arsort($fruits);

// Example of sorting an associative array by keys in ascending order
$colors = ['b' => 'blue', 'a' => 'red', 'c' => 'green'];
ksort($colors);