Bird
0
0

Which of the following is the correct syntax to use array_walk with a callback function named modify on an array $arr?

easy📝 Syntax Q12 of 15
PHP - Array Functions
Which of the following is the correct syntax to use array_walk with a callback function named modify on an array $arr?
Aarray_walk('modify', $arr);
Barray_walk(modify, $arr);
Carray_walk($arr, modify);
Darray_walk($arr, 'modify');
Step-by-Step Solution
Solution:
  1. Step 1: Recall array_walk syntax

    The correct syntax is array_walk(array, callback), where callback is a string with the function name.
  2. Step 2: Check the options

    Only array_walk($arr, 'modify'); matches the correct order and uses quotes around the callback function name.
  3. Final Answer:

    array_walk($arr, 'modify'); -> Option D
  4. Quick Check:

    array_walk(array, 'function') syntax [OK]
Quick Trick: array_walk takes array first, then callback as string [OK]
Common Mistakes:
  • Swapping the order of parameters
  • Omitting quotes around callback name
  • Passing callback without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes