Prior to PHP 5.3 this could work as well:
array_reduce(array(1,2,3,4,5), create_function('$v, $e', 'return $v | $e;'), 0); array_reduce(array(1,2,3,4,5), create_function('$v, $e', 'return $v | $e;'), 0);
For example, given a list of numbers, you can generate a bitwise OR mask easily:
What this does is iterate over the list and apply ($last_result | $current_element) and return the result, which is passed on as $last_result to the next iteration. $last_result is 0 by default. This is equivalent to (as of PHP 5.4): Or prior to PHP 5.3: It's doable in both languages, but Ruby's functional language lineage and its object-oriented nature results in an exceptionally clean approach.