Re: operators as callbacks?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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() ?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux