PHP - Type HandlingWhich of the following is the correct way to cast a variable $var to a boolean in PHP?Abool($var)B(bool) $varCcast bool $varD$var as boolCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand PHP casting syntaxPHP uses parentheses with the type name before the variable to cast types, e.g., (bool) $var.Step 2: Evaluate each option(bool) $var uses correct syntax. bool($var) looks like a function call, which is invalid. cast bool $var and D are not valid PHP syntax.Final Answer:(bool) $var -> Option BQuick Check:Type casting boolean = (bool) $var [OK]Quick Trick: Use (type) before variable to cast in PHP [OK]Common Mistakes:Using function-like syntax for castingWriting 'as' keyword for castingOmitting parentheses
Master "Type Handling" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Conditional Statements - If statement execution flow - Quiz 4medium Conditional Statements - Switch statement execution - Quiz 2easy Functions - Function declaration and calling - Quiz 2easy Loops - Break statement with levels - Quiz 6medium Operators - Logical operators - Quiz 10hard PHP Basics and Execution Model - How PHP executes on the server - Quiz 14medium PHP Basics and Execution Model - What is PHP - Quiz 6medium Type Handling - Gettype and typeof checks - Quiz 5medium Type Handling - Why type awareness matters - Quiz 13medium Variables and Data Types - Type juggling in PHP - Quiz 8hard