Bird
0
0

What is the correct syntax to cast a variable $num to a string in PHP?

easy📝 Conceptual Q2 of 15
PHP - Type Handling
What is the correct syntax to cast a variable $num to a string in PHP?
A$num->string()
B(string) $num
Cstring($num)
Dcast string $num
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP casting syntax for strings

    PHP casts to string by placing (string) before the variable.
  2. Step 2: Check each option

    (string) $num is correct syntax. Options A, B, and D are invalid in PHP.
  3. Final Answer:

    (string) $num -> Option B
  4. Quick Check:

    Type casting string = (string) $num [OK]
Quick Trick: Cast to string with (string) before variable [OK]
Common Mistakes:
  • Using function call syntax
  • Using object method syntax
  • Writing 'cast' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes