Re: operators as callbacks?
| From: | Martin Zvarík | Date: | Sun, 30 Nov 2008 00:59:49 +0000 |
| Subject: | Re: operators as callbacks? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283921@lists.php.net to get a copy of this message | ||
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() ?