Bird
0
0

Which of the following is the correct way to access a form field named username using $_REQUEST in PHP?

easy📝 Syntax Q12 of 15
PHP - Superglobals and Web Context
Which of the following is the correct way to access a form field named username using $_REQUEST in PHP?
A$_REQUEST->username
Brequest['username']
C$_REQUEST.username
D$_REQUEST['username']
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP array syntax

    PHP superglobals like $_REQUEST are associative arrays accessed with square brackets and quotes for keys.
  2. Step 2: Identify correct syntax for accessing 'username'

    The correct syntax is $_REQUEST['username']. Using arrows or dots is invalid for arrays.
  3. Final Answer:

    $_REQUEST['username'] -> Option D
  4. Quick Check:

    Array access uses brackets and quotes [OK]
Quick Trick: Use square brackets with quotes for $_REQUEST keys [OK]
Common Mistakes:
  • Using object notation (->) instead of array syntax
  • Using dot notation like in JavaScript
  • Forgetting quotes around the key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes