PHP - OperatorsWhat does the null coalescing operator ?? do in PHP?AReturns the first operand if it is not null, otherwise returns the second operand.BReturns true if both operands are null.CChecks if a variable is set and throws an error if not.DAssigns null to a variable if it is not already set.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand the operator's purposeThe null coalescing operator ?? checks if the left value is null.Step 2: Determine the returned valueIf the left value is not null, it returns that; otherwise, it returns the right value.Final Answer:Returns the first operand if it is not null, otherwise returns the second operand. -> Option AQuick Check:Null coalescing operator returns first non-null value [OK]Quick Trick: Remember: returns first non-null value [OK]Common Mistakes:Thinking it returns true/falseConfusing it with the ternary operatorAssuming it throws errors if variable is unset
Master "Operators" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Arrays - Multidimensional arrays - Quiz 2easy Arrays - Array sort functions - Quiz 10hard Conditional Statements - Why conditional flow is needed - Quiz 12easy Operators - Spaceship operator - Quiz 7medium PHP Basics and Execution Model - PHP CLI vs web server execution - Quiz 14medium PHP Basics and Execution Model - Comments in PHP - Quiz 8hard PHP Basics and Execution Model - PHP Installation and Setup - Quiz 15hard PHP Request Lifecycle - Why variables do not persist between requests - Quiz 4medium PHP Request Lifecycle - Script execution and memory reset - Quiz 14medium Type Handling - Type casting syntax - Quiz 12easy