adding value to each attribute in array

Hi this title should sound like: ‘change one function into second on buton click’ I have array with years in my controller:

public function getNextYear() {





    $years = $this->getYears();


    foreach ($years as $key => $value) {


        $y[] = $value + 1;


    }


    return $y;


}[/code]

I display this in my index in for loop:


  <?php foreach ($years as $year): ?>


        <div class="">

          

            <?= $year; ?><br>

           

        </div>

        

    <?php endforeach; ?>

<?php endif; ?><br>

I want to add +1 to each year in my array

This is a client side (javascript) question.

The solution could be similar at:




  <?php foreach ($years as $year): ?>


        <div class="year_value">

          

            <?= $year; ?>

           

        </div>

        <?php foreach ($blog->getMonths() as $key => $value): ?>

           

                <div class="">

                    <?= Html::a($value, Url::to(['post-month', 'id' => $key, 'year' => $year])); ?>

                    <?php if(BlogPost::getPostsPerMonth($key, $year)->count()>0):?>  

                    <?= BlogPost::getPostsPerMonth($key, $year)->count() ?>

                    <?php endif; ?>

                </div>

           

        <?php endforeach; ?>

    <?php endforeach; ?>

<?php endif; ?><br>






$(document).on('click', '#btnToClick', function(ev) {

   $('div.year_value').each(function() {

        var currValue = intVal($(this).html());

        $(this).html = currValue+1;

   });

});



If you don’t know javascript, you could solve your problem reloading the page, otherwise I suggest you to learn Javascript and JQuery.

Simply add a button or link:




<button id="btnToClick">button to click</button>



or




<a href="#;" id="buttonToClick">Button to click</a>