A. PHP converts '5 cats' to 5, so 5 - 3 = 2, which might be unexpected if you expect string behavior.
B. Because subtraction is not defined for strings, it causes a fatal error.
C. The variable $result will be the string '5 cats3' due to concatenation.
D. PHP treats both as strings and outputs '5 cats3'.
Solution
Step 1: Analyze subtraction with string and integer
PHP converts the string '5 cats' to the number 5 for arithmetic operations.
Step 2: Calculate the subtraction
5 - 3 equals 2, so $result is 2, which may surprise if expecting string concatenation or error.
Final Answer:
PHP converts '5 cats' to 5, so result is 2 -> Option A
Quick Check:
'5 cats' - 3 = 2 [OK]
Hint: Subtraction forces string to number conversion [OK]
Common Mistakes:
Expecting string concatenation with - operator
Thinking it causes an error
Assuming result is a string
5. You want to compare two variables in PHP: $a = '0' (string) and $b = false (boolean). Which comparison returns true when using type coercion, and which returns false when checking type strictly?
Choose the correct pair:
hard
A. $a == $b is true; $a === $b is false
B. $a == $b is false; $a === $b is true
C. $a == $b is true; $a === $b is true
D. $a == $b is false; $a === $b is false
Solution
Step 1: Understand loose (==) vs strict (===) comparison
Loose comparison converts types before comparing; strict compares value and type exactly.
Step 2: Evaluate comparisons
Loose: '0' converts to 0, false converts to 0, so 0 == 0 is true. Strict: '0' is string, false is boolean, types differ, so false.
Final Answer:
$a == $b is true; $a === $b is false -> Option A
Quick Check:
'0' == false is true; '0' === false is false [OK]
Hint: Use === to check type and value, == allows type coercion [OK]
Common Mistakes:
Assuming == checks type strictly
Thinking '0' and false are always different
Confusing loose and strict equality
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.