Programming MCQs Feed

📊 PHP
Q. Which PHP function reverses an array?
  • (A) array_flip()
  • (B) array_reverse()
  • (C) array_swap()
  • (D) array_sort()
💬 Discuss
✅ Correct Answer: (B) array_reverse()

Explanation: array_reverse() reverses array order.

📊 PHP
Q. Which PHP function flips array keys and values?
  • (A) array_reverse()
  • (B) array_change_key_case()
  • (C) array_flip()
  • (D) array_swap()
💬 Discuss
✅ Correct Answer: (C) array_flip()

Explanation: array_flip() swaps keys and values.

📊 PHP
Q. Which PHP function removes duplicate values from an array?
  • (A) array_unique()
  • (B) array_distinct()
  • (C) unique_array()
  • (D) array_remove_duplicates()
💬 Discuss
✅ Correct Answer: (A) array_unique()

Explanation: array_unique() removes duplicate values.

📊 PHP
Q. Which PHP function joins array elements into a string?
  • (A) join()
  • (B) implode()
  • (C) Both join() and implode()
  • (D) concat()
💬 Discuss
✅ Correct Answer: (C) Both join() and implode()

Explanation: join() is an alias of implode().

📊 PHP
Q. Which PHP function escapes HTML characters?
  • (A) htmlspecialchars()
  • (B) strip_tags()
  • (C) htmlentities()
  • (D) escape_html()
💬 Discuss
✅ Correct Answer: (A) htmlspecialchars()

Explanation: htmlspecialchars() prevents XSS by escaping HTML.

📊 PHP
Q. What will be the output of: var_dump(false == 0);
  • (A) true
  • (B) false
  • (C) 0
  • (D) Error
💬 Discuss
✅ Correct Answer: (A) true

Explanation: Loose comparison converts false to 0.

📊 PHP
Q. What will be the output of: var_dump(false === 0);
  • (A) true
  • (B) false
  • (C) 0
  • (D) Error
💬 Discuss
✅ Correct Answer: (B) false

Explanation: Strict comparison checks both value and type.

📊 PHP
Q. Which PHP construct is faster than calling a function?
  • (A) print
  • (B) echo
  • (C) printf
  • (D) var_dump
💬 Discuss
✅ Correct Answer: (B) echo

Explanation: echo is a language construct and faster than functions.

📊 PHP
Q. Which PHP function returns the last element of an array without removing it?
  • (A) end()
  • (B) array_last()
  • (C) array_pop()
  • (D) last()
💬 Discuss
✅ Correct Answer: (A) end()

Explanation: end() moves the internal pointer to the last element.

📊 PHP
Q. Which PHP function resets the internal pointer of an array?
  • (A) reset()
  • (B) rewind()
  • (C) start()
  • (D) first()
💬 Discuss
✅ Correct Answer: (A) reset()

Explanation: reset() sets the array pointer to the first element.