Which of the following are true about sorting arrays in PHP?
- Sorting can be performed on both indexed and associative arrays.
- Sorting modifies the original array.
- Sorting is always done in ascending order.
- Sorting is only applicable to numeric arrays.
The correct option is 1. Sorting can be performed on both indexed and associative arrays in PHP. You can sort arrays based on their values while maintaining key-value associations (for associative arrays) or simply rearrange the elements in ascending or descending order (for indexed arrays). The sort() and rsort() functions modify the original array, while functions like asort(), ksort(), arsort(), and krsort() maintain the original array and sort it based on certain criteria. Sorting in PHP is not limited to numeric arrays; it can be applied to arrays with various types of values. Learn more: https://www.php.net/manual/en/array.sorting.php
Loading...
Related Quiz
- A common use case for the $_GET superglobal in PHP is to collect the data sent in the ______.
- You are writing a PHP script and you need to define a trait. How would you do this?
- How is the ternary conditional operator used in PHP?
- Comments in PHP can be used to leave notes in the code for other developers.
- You have a PHP script and you need to access data sent via the GET method from a form. How would you do this using the $_GET superglobal?