Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - String Functions
What will be the output of the following PHP code?
$text = "Programming";
echo substr($text, 3, 4);
Agram
Bgramm
Cming
DProg
Step-by-Step Solution
Solution:
  1. Step 1: Identify substring start and length

    Start index is 3, length is 4. Counting from 0: P(0), r(1), o(2), g(3).
  2. Step 2: Extract substring

    Characters at positions 3,4,5,6 are g, r, a, m, forming "gram".
  3. Final Answer:

    gram -> Option A
  4. Quick Check:

    substr from 3 length 4 = "gram" [OK]
Quick Trick: Count start index from 0, length counts chars after start [OK]
Common Mistakes:
  • Counting start from 1
  • Including wrong number of characters
  • Confusing substring with slice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes