On Sat, Nov 29, 2008 at 5:59 PM, Martin Zvarík <[EMAIL PROTECTED]> wrote:

> Joe napsal(a):
>
>> Is it possible to use a PHP operator as a callback? Suppose I want to add
>> two
>> arrays elementwise, I want to be able to do something like this:
>>  array_map('+', $array1, $array2)
>> but this doesn't work as "+" is an operator and not a function.
>>
>> I can use the BC library's math functions instead:
>>  array_map('bcadd', $array1, $array2)
>> but that is an ugly hack that might break if the library is not available.
>>
>> I can create an anonymous function:
>>  array_map(create_function('$a, $b', 'return $a + $b;'), $array1, $array2)
>> but that seems really unnecessarily verbose.
>>
>> Is there any simple clean way to do it? Thanks,
>>
>>
>>
> array_sum() ?


no, if you bother to read OPs examples, it should be clear that he is not
trying to sum the arrays in this manor.  i thought to try array_sum() at
first, but then actually re-read the post, to realize that any use of
array_sum() to solve this problem would be rather convoluted.  at least i
couldnt contrive an array_sum() solution worth posting...

-nathan

Reply via email to