PHP - ArraysWhich of the following creates an indexed array with the elements "red", "green", and "blue"?A$colors = <"red", "green", "blue">;B$colors = {"red", "green", "blue"};C$colors = ("red", "green", "blue");D$colors = array("red", "green", "blue");Check Answer
Step-by-Step SolutionSolution:Step 1: Recall PHP array creation functionsPHP supports array creation using the array() function or square brackets [].Step 2: Identify valid syntaxThe syntax $colors = array("red", "green", "blue"); correctly creates an indexed array with three string elements.Final Answer:$colors = array("red", "green", "blue"); -> Option DQuick Check:Indexed array creation with array() = $colors = array("red", "green", "blue"); [OK]Quick Trick: Use array() or [] to create arrays in PHP [OK]Common Mistakes:Using curly braces {} which are invalid for arraysUsing parentheses () without array keywordUsing angle brackets <> which are invalid
Master "Arrays" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Conditional Statements - If statement execution flow - Quiz 12easy Functions - Why functions are needed - Quiz 11easy Loops - Foreach loop for arrays - Quiz 7medium Operators - Arithmetic operators - Quiz 1easy Operators - Logical operators - Quiz 13medium Output and String Handling - Escape sequences in strings - Quiz 10hard Output and String Handling - String interpolation in double quotes - Quiz 2easy Output and String Handling - Heredoc and nowdoc syntax - Quiz 6medium PHP Basics and Execution Model - PHP Installation and Setup - Quiz 4medium PHP Request Lifecycle - Comparison with long-running servers (Node.js) - Quiz 6medium