Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q4 of 15
PHP - Sessions and Cookies
What will this PHP code output?
<?php
session_start();
$_SESSION['count'] = 1;
$_SESSION['count']++;
echo $_SESSION['count'];
?>
A1
BError
C2
D0
Step-by-Step Solution
Solution:
  1. Step 1: Understand session variable assignment

    $_SESSION['count'] is set to 1 initially.
  2. Step 2: Increment the session variable

    $_SESSION['count']++ increases it by 1, making it 2.
  3. Final Answer:

    2 -> Option C
  4. Quick Check:

    Increment session variable = 2 [OK]
Quick Trick: Increment session variable to increase count [OK]
Common Mistakes:
  • Thinking it stays 1
  • Expecting zero
  • Assuming syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes