[php-src] Issue #10091: RFE: array/scalar maths functions

From: Date: Tue, 13 Dec 2022 00:42:31 +0000
Subject: [php-src] Issue #10091: RFE: array/scalar maths functions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243117@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10091 Author: RichardNeill ### Description It would be nice if we could do the "obvious" mathematical operations between arrays and scalars. E.g. ``` $arr = [1,2,3]; $arr+1 # [2,3,4]; $arr*2 # [2,4,6]; ``` etc for +,-,/,*, and the bitwise, logical ones. In my view, this should apply the operation to every value (even in multi-dimensional arrays) without changing the keys. At the moment, all of these create fatal errors, which means that nobody can be using this syntax, and it would be OK to add it without it being a breaking-change. Alternatively, could we have array_adds(), array_muls(), etc functions? I know we can already do this with foreach, or anonymous functions, or callbacks, but it's so much less readable. Thanks!

« previous php.bugs (#243117) next »