history.pushState是否在页面上重新定义变量?

I'm using history.pushState() in my wordpress site to changes the url/title of the page once a new post is dynamically loaded (AJAX). I want to store each post's id in an array, but for some reason the array variable gets re-defined.

At the top of my page I define the array variable:

<?php $array = array(); ?>

So when I push data to the array it only pushes to index 0.

Some help would be greatly appreciated.

pushState changes only the history stack.

It doesn't change any other variable accessible to JavaScript.

It couldn't possibly change any PHP variable because it runs on the client and does not trigger any HTTP request.

PHP is server side and is evaluated once and for all on each load. Hence why it is 0.

As @Quentin says in his answer: history.pushState is JavaScript (front-end). It has no connection with PHP (back-end) whatsoever.