Bird
0
0

Which of the following PHP code snippets correctly extracts all keys from the array $data?

easy📝 Syntax Q3 of 15
PHP - Array Functions
Which of the following PHP code snippets correctly extracts all keys from the array $data?
A<code>$keys = keys($data);</code>
B<code>$keys = array_values($data);</code>
C<code>$keys = array_keys($data);</code>
D<code>$keys = get_keys($data);</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function purpose

    array_keys() returns all keys from an array, while array_values() returns values.
  2. Step 2: Identify correct syntax

    The correct syntax to extract keys is array_keys($data).
  3. Final Answer:

    $keys = array_keys($data); -> Option C
  4. Quick Check:

    Verify function names and their purposes in PHP docs [OK]
Quick Trick: array_keys() extracts keys, array_values() extracts values [OK]
Common Mistakes:
  • Confusing array_keys() with array_values()
  • Using non-existent functions like keys() or get_keys()
  • Incorrect function syntax or missing parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes