LinkedIn PHP Skill Quiz Assessment Answers

The PHP function array_reduce() takes a callback function that accepts a value carried over each iteration and the current item in the array, and reduces an array to a single value. Which code sample will sum and output the values in the provided array?

Latest Update on 30th December, 2021 by Certification Course Answers

The PHP function array_reduce() takes a callback function that accepts a value carried over each iteration and the current item in the array, and reduces an array to a single value. Which code sample will sum and output the values in the provided array?

  1. [ ]
    1 <?php
    2 echo array_reduce([1, 2, 5, 10, 11], function ($item, $carry) {
    3 $carry = $carry + \$item;
    4 });
    5?>
  2. [ ]
    1 <?php
    2 echo array_reduce([1, 2, 5, 10, 11], function ($carry, $item) {
    3 return $carry = $item + \$item;
    4 });
    5?>
  3. [ ]
    1 <?php
    2 array_reduce([11 2, 5, 10, 11], function ($item, $carry) {
    3 echo $carry + $item;
    4 });
    5?>
  4. [X]
    1 <?php –CORRECT
    2 echo array_reduce([1, 2, 5, 10, 11], function ($carry, $item) {
    3 return $carry += $item;
    4 });
    5?>

Correct Answer:

  • [x]
    1 <?php –CORRECT
    2 echo array_reduce([1, 2, 5, 10, 11], function ($carry, $item) {
    3 return $carry += $item;
    4 });
    5?>

Latest Updates

No posts found in this category.