Hey Rowan, <http://ocramius.github.com/>
On Thu, Sep 12, 2019 at 3:30 PM Rowan Tommins <rowan.coll...@gmail.com> wrote: > For instance, for undefined array keys, what if we had an operator for > "initialise and retrieve", such as $foo[? 'bar']. Then we could simplify > ugly code like this: > > if ( ! isset($foo[$key1]) { > $foo[$key1] = []; > } > if ( ! isset($foo[$key1][$key2]) { > $foo[$key1][$key2] = 0; > } > $foo[$key1][$key2]++; > > > With something safe but succinct like this: > > $foo[? $key1][? $key2]++; > $foo[$key1][$key2] = ($foo[$key1][$key2] ?? 0) + 1; Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/