Programming MCQs Feed

📊 PHP
Q. Which PHP interface allows objects to be accessed like arrays?
  • (A) Iterator
  • (B) Traversable
  • (C) ArrayAccess
  • (D) Countable
💬 Discuss
✅ Correct Answer: (C) ArrayAccess

Explanation: ArrayAccess provides array-like access.

📊 PHP
Q. Which PHP interface allows count() to work on objects?
  • (A) Countable
  • (B) Iterable
  • (C) Iterator
  • (D) ArrayAccess
💬 Discuss
✅ Correct Answer: (A) Countable

Explanation: Countable enables count() on objects.

📊 PHP
Q. Which PHP extension is recommended for secure database access?
  • (A) mysql
  • (B) mysqli
  • (C) PDO
  • (D) odbc
💬 Discuss
✅ Correct Answer: (C) PDO

Explanation: PDO supports prepared statements and multiple databases.

📊 PHP
Q. Which PDO fetch mode returns an associative array?
  • (A) PDO::FETCH_NUM
  • (B) PDO::FETCH_OBJ
  • (C) PDO::FETCH_ASSOC
  • (D) PDO::FETCH_BOTH
💬 Discuss
✅ Correct Answer: (C) PDO::FETCH_ASSOC

Explanation: FETCH_ASSOC returns column names as keys.

📊 PHP
Q. Which PDO fetch mode returns an object?
  • (A) PDO::FETCH_OBJ
  • (B) PDO::FETCH_NUM
  • (C) PDO::FETCH_ASSOC
  • (D) PDO::FETCH_CLASS
💬 Discuss
✅ Correct Answer: (A) PDO::FETCH_OBJ

Explanation: FETCH_OBJ returns results as anonymous objects.

📊 PHP
Q. Which method fetches all rows from a PDO result set?
  • (A) fetch()
  • (B) fetchRow()
  • (C) fetchAll()
  • (D) getAll()
💬 Discuss
✅ Correct Answer: (C) fetchAll()

Explanation: fetchAll() retrieves all records at once.

📊 PHP
Q. Which PHP function hashes a password securely?
  • (A) md5()
  • (B) sha1()
  • (C) password_hash()
  • (D) crypt()
💬 Discuss
✅ Correct Answer: (C) password_hash()

Explanation: password_hash() uses strong hashing algorithms.

📊 PHP
Q. Which PHP function prevents Cross-Site Scripting (XSS)?
  • (A) strip_tags()
  • (B) htmlspecialchars()
  • (C) htmlentities()
  • (D) All of the above
💬 Discuss
✅ Correct Answer: (D) All of the above

Explanation: All help sanitize HTML output.

📊 PHP
Q. Which PHP function removes HTML and PHP tags?
  • (A) htmlspecialchars()
  • (B) htmlentities()
  • (C) strip_tags()
  • (D) remove_tags()
💬 Discuss
✅ Correct Answer: (C) strip_tags()

Explanation: strip_tags() removes all HTML and PHP tags.

📊 PHP
Q. Which HTTP method is considered safest for retrieving data?
  • (A) POST
  • (B) PUT
  • (C) DELETE
  • (D) GET
💬 Discuss
✅ Correct Answer: (D) GET

Explanation: GET is read-only and does not modify server state.