How can an array in PHP be sorted alphabetically?
To sort an array alphabetically in PHP, you can use the `sort()` function. This function will rearrange the elements of the array in alphabetical order. You can also use the `asort()` function if you want to maintain the key-value associations while sorting the array alphabetically.
// Example array to be sorted alphabetically
$fruits = array("Apple", "Banana", "Orange", "Mango");
// Sorting the array alphabetically
sort($fruits);
// Output the sorted array
print_r($fruits);
Keywords
Related Questions
- What are the potential reasons for a PHP script not creating or writing to a file using file_put_contents?
- In what ways can JavaScript be used to execute HTTP requests in PHP scripts for seamless image generation and display?
- What are the potential consequences of not using proper error reporting in PHP?