PHP, CSS, and JS speakers! )
I am including a menu in a php file. I need it, because it takes less time to change the links. However, the task is now with **ACTIVE links**. When I click a link, *it should take the active as well as the parent links also should take an active link*.
I did it with PHP, which works fine , but if I continue, there will be a lot of php statements and **it may also affect the performance**, and it has a bad affect on *readability* of the code. Please have a look at the below code (this is just a FRAGMENT) of the code, i.e. 1 section of the menu, not the whole menu )

```
  <!--  TAJIKISTAN section start -->
          <li class="megamenu"><a   <?php if($activePageL0 == "tajikistan") { echo "class = \"mn-has-sub active button_open \" "; }else {echo "class = \"mn-has-sub button_open \" ";} ?> >Tajikistan <i class="fa fa-angle-down button_open"></i></a>
            <!-- Sub-->
            <ul class="mn-sub mn-has-multi">
             <li <?php if($activePageL1 == "tajikistan-sub") { echo "class = \"mn-sub-multi active button_open\" "; }else {echo "class = \" mn-sub-multi button_open \" ";} ?> > <a class="mn-group-title button_open">Tajikistan</a>
                <ul>
                  <li <?php if($activePageL2 == "tajikistan-history") { echo "class = \"active\" "; }else {echo "class = \" \" ";} ?> ><a href="<?php echo "$root/$lang"; ?>/tajikistan-history.php">History</a></li>
                  <li><a href="#">Culture </a></li>
                  <li><a href="#">Holidays</a></li>
                  <li><a href="#">Short info</a></li>
                </ul>
              </li>
              <li class="mn-sub-multi"><a class="mn-group-title">Mountains</a>
                <ul>
                  <li><a href="#">The Pamirs</a></li>
                  <li><a href="#">Fann </a></li>
                  <li><a href="#">Peak Ismoili Somoni</a></li>
                  <li><a href="#">K.Marx & F.Engles</a></li>

                </ul>
              </li>

            </ul>
            <!-- End Sub-->
          </li>
           <li class="slash">/</li>
           <!-- End Tajikistan -->

```

Question: Is there any way to handle it with PHP or Java Script or anything?

Thank you in advance!