如何优化很多if循环?

This goes on 12 times:

    if (isset($this->month1)) {
        array_push($monthly, "Month 1: " . $this->month1)
    }

    if (isset($this->month2)) {
        array_push($monthly, "Month 2: " . $this->month2)
    }

    if (isset($this->month3)) {
        array_push($monthly, "Month 3: " . $this->month3)
    }

Anyway to optimize this?

You could do something like:

foreach (range(1, 12) as $i) {
    $param = 'month' . $i;
    if (isset($this->$param)) {
        array_push($monthly, "Month $i: " . $this->$param);
    }
}

Hope this helps!