@panigrc I also thought of something similar after posting this :D
I'm still not sure which one I prefer though. This one may be easier to understand, but the performance is not as good. Of course, that depends on whether performance is important or not, the context of the project where this is being developed, etc.
I was vague on purpose to see how people react.
@noeldemartin I would use the https://www.php.net/manual/en/datetime.sub.php
Within a loop subtracting 1 month each time and adding the result to an array.