Bird
0
0

Which of the following is the correct syntax to pad an array $arr to size 5 with the value 0 using array_pad?

easy📝 Syntax Q12 of 15
PHP - Array Functions
Which of the following is the correct syntax to pad an array $arr to size 5 with the value 0 using array_pad?
A$padded = array_pad($arr, 5);
B$padded = array_pad(5, $arr, 0);
C$padded = array_pad($arr, 5, 0);
D$padded = array_pad($arr, 0, 5);
Step-by-Step Solution
Solution:
  1. Step 1: Recall array_pad syntax

    The correct syntax is array_pad(array, size, value), where the first argument is the array, second is the desired size, third is the padding value.
  2. Step 2: Check each option

    $padded = array_pad($arr, 5, 0); matches the correct order and arguments. Options B and C have wrong argument order. $padded = array_pad($arr, 5); misses the padding value.
  3. Final Answer:

    $padded = array_pad($arr, 5, 0); -> Option C
  4. Quick Check:

    array_pad(array, size, value) correct order [OK]
Quick Trick: Remember: array_pad(array, size, value) [OK]
Common Mistakes:
  • Swapping argument order
  • Omitting the padding value
  • Passing size as first argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes