>> $foo[$key1][$key2] = ($foo[$key1][$key2] ?? 0) + 1; > That violates blatantly DRY (twice the exact same lengthy expression `$foo[$key1][$key2]`), so it is not a satisfactory solution.
$foo[$key1][$key2]??++ 😃 More seriously, yes as Marco suggested, yes we can already do it, and as Claude pointed out, yes that's verbose. What I had in mind with language support is some kind of code-level (per line or block) switch that would allow uninitialized array keys to behave in a certain way, *depending on the context* : we actually have not one, but two good examples of this above, provided that $key1 and $key2 do not exist: - with , an unitialized key would be initialized with an empty array (already does that) - with ++, an unitialized key would be initialized with 0 Without the proper code-level switch, we could safely have both cases above throw an exception. — Benjamin