What is the difference between sort() and rsort() in PHP?

  • sort() sorts the array in ascending order, while rsort() sorts it in descending order.
  • sort() works on indexed arrays, while rsort() works on associative arrays.
  • sort() modifies the original array, while rsort() returns a new sorted array.
  • sort() and rsort() have the same functionality.
The correct option is 1. The main difference between sort() and rsort() in PHP is the order in which they sort the array. The sort() function arranges the elements of an array in ascending order, while the rsort() function sorts the elements in descending order. Both functions work on indexed arrays, not specifically on associative arrays. Additionally, both sort() and rsort() modify the original array directly, rather than returning a new sorted array. Understanding the difference between these functions is important for selecting the appropriate sorting method based on the desired order of the array elements. Learn more: https://www.php.net/manual/en/function.sort.php, https://www.php.net/manual/en/function.rsort.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *