Bird
0
0

What does the following PHP code do?

easy📝 Conceptual Q11 of 15
PHP - Type Handling
What does the following PHP code do?
$num = (int) "123";
AConverts the string "123" to an integer 123
BConverts the integer 123 to a string
CThrows a syntax error
DLeaves the variable as a string
Step-by-Step Solution
Solution:
  1. Step 1: Identify the type casting operation

    The code uses (int) before a string variable, which means it converts the string to an integer.
  2. Step 2: Understand the conversion result

    The string "123" becomes the integer 123 after casting.
  3. Final Answer:

    Converts the string "123" to an integer 123 -> Option A
  4. Quick Check:

    Type casting (int) converts string "123" to integer 123 [OK]
Quick Trick: Casting (int) changes strings of digits to numbers [OK]
Common Mistakes:
  • Thinking it converts integer to string
  • Expecting a syntax error
  • Assuming the variable stays a string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes