PHP Array function-array_reduce ()

Source: Internet
Author: User

The Array_reduce () function sends a value from the array to the user-defined function and returns a string. Note: If the array is empty or the initialization value is not passed, the function returns Nullarray_reduce (array,myfunction,initial); array: Required. Specify array MyFunction: Required. Specifies the name of the function initial: optional. Specifies the first value sent to the function to be processed <?php
functionMyFunction$v 1,$v 2)
{
Echo$v 1.‘ ----‘.$v 2.‘ <br> ';
return$v 1+$v 2;
}
$a=Array(10,15,20);
Print_r(Array_reduce($a, "MyFunction", 5));
?> output: 5----1015----1530----2050

PHP Array function-array_reduce ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.