PHP - ArraysWhy does the PHP function asort() preserve keys while sorting values, but sort() does not?Asort() preserves keys only if array is numericBasort() sorts values and maintains key association; sort() reindexes keysCasort() only works on associative arrays; sort() only on indexed arraysDsort() sorts keys, asort() sorts valuesCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand asort() behaviorasort() sorts values ascending and keeps original keys linked to values.Step 2: Understand sort() behaviorsort() sorts values ascending but resets keys to numeric indexes starting at 0.Final Answer:asort() sorts values and maintains key association; sort() reindexes keys -> Option BQuick Check:asort() preserves keys, sort() resets keys [OK]Quick Trick: asort() keeps keys; sort() resets keys [OK]Common Mistakes:Thinking sort() sorts keysBelieving asort() only works on associative arraysAssuming sort() preserves keys for numeric arrays
Master "Arrays" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Arrays - Why arrays are essential in PHP - Quiz 13medium Functions - Nullable types in functions - Quiz 4medium Functions - Variable scope in functions - Quiz 10hard Loops - Do-while loop execution model - Quiz 10hard Operators - Why operators matter - Quiz 9hard Output and String Handling - Why output functions matter - Quiz 1easy PHP Basics and Execution Model - What is PHP - Quiz 3easy PHP Request Lifecycle - Why global state is dangerous in PHP - Quiz 7medium PHP Request Lifecycle - Comparison with long-running servers (Node.js) - Quiz 5medium Type Handling - Type casting syntax - Quiz 11easy