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
Loading...
Related Quiz
- To delete a cookie in PHP, you can use the setcookie() function with an expiration date in the ______.
- You have a PHP script and you need to get the URL of the current page. How would you do this using the $_SERVER superglobal?
- How is the comparison of objects done in PHP?
- You need to store a collection of key-value pairs in your PHP script. How would you do this using an array?
- Explain the concept of anonymous functions (closures) in PHP. How are they used and what are their advantages?