What function can be used to sort an array in PHP?
To sort an array in PHP, you can use the `sort()` function. This function sorts an array in ascending order based on its values. If you need to sort an array in descending order, you can use the `rsort()` function. Both functions modify the original array.
$numbers = [4, 2, 8, 5, 1];
sort($numbers);
print_r($numbers);
Related Questions
- Are there any best practices for generating random numbers in PHP to ensure uniqueness?
- In PHP, what are the best practices for integrating database content into different pages of a website and ensuring correct display based on URLs?
- What are some best practices for handling date calculations in PHP, particularly when excluding weekends from the calculation?