Bird
0
0

What does the PHP function array_filter() do when applied to an array?

medium📝 Predict Output Q5 of 15
PHP - Array Functions
What does the PHP function array_filter() do when applied to an array?
ACounts the number of elements
BRemoves duplicate values
CSorts the array in descending order
DFilters elements based on a callback function
Step-by-Step Solution
Solution:
  1. Step 1: Recall the purpose of array_filter()

    array_filter() keeps elements that pass a test defined by a callback function.
  2. Step 2: Eliminate incorrect options

    It does not remove duplicates, sort, or count elements.
  3. Final Answer:

    Filters elements based on a callback function -> Option D
  4. Quick Check:

    array_filter() = filter with callback [OK]
Quick Trick: Use array_filter() to keep elements matching a condition [OK]
Common Mistakes:
  • Thinking it removes duplicates
  • Confusing with sort or count functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes