note 43822 added to function.array-filter
| From: | marc dot vanwoerkom at fernuni-hagen dot de | Date: | Mon, 05 Jul 2004 12:09:16 +0000 |
| Subject: | note 43822 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72605@lists.php.net to get a copy of this message | ||
Some of PHP's array functions play a prominent role in so called functional programming
languages, where they show up under a slightly different name:
array_filter() -> filter(),
array_map() -> map(),
array_reduce() -> foldl() ("fold left")
Functional programming is a paradigm which centers around the side-effect free evaluation of
functions. A program execution is a call of a function, which in turn might be defined by many other
functions. One idea is to use functions to create special purpose functions from other functions.
The array functions mentioned above allow you compose new functions on arrays.
E.g. array_sum = array_map("sum", $arr).
This leads to a style of programming that looks much like algebra, e.g. the Bird/Meertens formalism.
E.g. a mathematician might state
map(f o g) = map(f) o map(g)
the so called "loop fusion" law.
Many functions on arrays can be created by the use of the foldr() function (which works like foldl,
but eating up array elements from the right).
I can't get into detail here, I just wanted to provide a hint about where this stuff also shows
up and the theory behind it.
----
Manual Page -- http://www.php.net/manual/en/function.array-filter.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43822
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43822&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43822&report=yes
Search -- http://master.php.net/manage/user-notes.php