You can't directly set variables from javascript to php. You will need to either force the page to post data or redirect (which will cause the page to reload), or use AJAX to send the data to the server to be saved for later use.
PHP code is execute on the server side, and any output is then sent to the client device (whatever called the php file). Any manipulation of that output data isn't saved unless you send it back to the server.