I am trying to increment php variable after some action happens in javascript. The problem is that the variable will increment only once (from 0 to 1). After that it stays as 1. I would like it to increment to 2 and so on after the action in JS is finished. Here is my code:
<script>
         // create youtube player
            var player;
        //$array = just an array of strings
        //$array_position = position in array
            <?php $array_position = 0; ?> 
            function onYouTubePlayerAPIReady() {
                player = new YT.Player('player', {
                width: '640',
                height: '390',
                videoId: '<?php echo $array[$array_position];?>',
                events: {
                          onStateChange: onPlayerStateChange
                        }
                });
            }
    // when video ends the $array_poisition should increment everytime
            function onPlayerStateChange(event) {      
                if(event.data === 0) { 
                    <?php
                        $array_position++;
                    ?>
                //change the id of the video
            player.loadVideoById('<?php echo $array[$array_position];?>');
                }
            }
</script>
Thanks for any advice.
 
     
    