Bird
0
0

Which PHP function returns the key of a value in an array if found, or false if not found?

easy📝 Conceptual Q11 of 15
PHP - Arrays
Which PHP function returns the key of a value in an array if found, or false if not found?
A<code>in_array</code>
B<code>array_search</code>
C<code>array_key_exists</code>
D<code>array_keys</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand function purpose

    array_search looks for a value and returns its key if found.
  2. Step 2: Compare with other functions

    in_array returns true/false, not key; array_key_exists checks keys; array_keys returns all keys.
  3. Final Answer:

    array_search -> Option B
  4. Quick Check:

    Key returned by array_search = array_search [OK]
Quick Trick: array_search returns key, in_array returns true/false [OK]
Common Mistakes:
  • Confusing array_search with in_array
  • Thinking array_key_exists returns value
  • Assuming array_keys searches values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes