Bird
0
0

What does the PHP function array_filter do to an array?

easy📝 Conceptual Q11 of 15
PHP - Array Functions
What does the PHP function array_filter do to an array?
AIt removes all keys from the array.
BIt keeps only the elements where the callback returns true.
CIt changes all values to strings.
DIt sorts the array in ascending order.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of array_filter

    The function array_filter tests each element with a callback function.
  2. Step 2: Determine what happens based on callback result

    Elements for which the callback returns true are kept; others are removed.
  3. Final Answer:

    It keeps only the elements where the callback returns true. -> Option B
  4. Quick Check:

    array_filter keeps elements with true callback [OK]
Quick Trick: Remember: true keeps, false removes elements [OK]
Common Mistakes:
  • Thinking array_filter sorts the array
  • Assuming it changes values to strings
  • Believing it removes keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes