Home >> PHP >> array_reduce() function in PHP

array_reduce() function in PHP

The array_reduce() function used for reduce the array to a single value using a user defined function.

Syntax

array_reduce(array,yourfunction,initial)

Example

function yourfunction($v1,$v2)
{
return $v1 . " " . $v2;
}
$a=array("Ram","Shyam","Ravi");
print_r(array_reduce($a,"yourfunction"));

Output

Ram Shyam Ravi

Post Your Comment

Next Questions
array_reverse() function
array_search() function
array_shift() function
array_slice() function
array_splice() function
array_sum() function
array_udiff() function
array_udiff_assoc() function
array_udiff_uassoc() function
array_uintersect() function
array_uintersect_assoc() function
array_uintersect_uassoc() function
array_unique() function
array_unshift() function
array_values() function
array_walk() function
array_walk_recursive() function
asort() function
arsort() function
compact() function
count() function
current() function
each() function
end() function
extract() function

Copyright ©2022 coderraj.com. All Rights Reserved.