Bird
0
0

Which of the following is the correct syntax to use array_filter with a callback function named isPositive on array $numbers?

easy📝 Syntax Q12 of 15
PHP - Array Functions
Which of the following is the correct syntax to use array_filter with a callback function named isPositive on array $numbers?
A<code>array_filter($numbers, isPositive);</code>
B<code>array_filter($numbers, &isPositive);</code>
C<code>array_filter(isPositive, $numbers);</code>
D<code>array_filter($numbers, 'isPositive');</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall array_filter syntax

    The second argument must be a callable, passed as a string or anonymous function.
  2. Step 2: Identify correct callable format

    Passing the function name as a string, like 'isPositive', is correct.
  3. Final Answer:

    array_filter($numbers, 'isPositive'); -> Option D
  4. Quick Check:

    Callback function name as string [OK]
Quick Trick: Callback function names go in quotes [OK]
Common Mistakes:
  • Passing callback without quotes
  • Swapping argument order
  • Using & before function name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes