Null Coalesce Or Increment

My brain’s telling me there isnt a short(er)hand way of doing this, but I figured i’d throw it out and see if i’m just having a forrest for the trees moment.

What’s the shortest way to combine a null coalesce and increment?
IE: If I have a key for my array that may or may not exist, what’s the shortest I can either increment or set to 1.

My current line is:
$result[$status] = ($result[$status] ?? 0) + 1;

Looks pretty concise to me. Anything shorter would probably be too cryptic and destroy readability. No use overcomplicating it just to save a few more characters.

:slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.