PHP » PYTHON |
login |
register |
about
|
PYTHON array_reduce
is this article helpful?
|
Python replacement for PHP's array_reduce
[
edit
| history
]
# Python 2.x: reduce(function, input) reduce(function, input, initial) # Python 3.x: import functools functools.reduce(function, input) functools.reduce(function, input, initial) array_reduce(PHP 4 >= 4.0.5, PHP 5) array_reduce — Iteratively reduce the array to a single value using a callback function Descriptionarray_reduce() applies iteratively the function function to the elements of the array input , so as to reduce the array to a single value. Parameters
Return ValuesReturns the resulting value. If the array is empty and initial is not passed, array_reduce() returns NULL. Examples
Example #1 array_reduce() example
<?php This will result in $b containing 15, $c containing 1200 (= 10*1*2*3*4*5), and $d containing 1.
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|