To Answer your question, you need to understand how a page loads:
- Request to server.
- Server Processes request, load pages, run php, whatever needs to be done.
- Server outputs html,css,javascript, whatever the process from 2 tells it to.
- Finally, your browser interprets all the data and gives you a layout.
So, as you can see, php is run before javascript is even sent to the browser to be run. What you want to do is go backwards in the process, this is not possible.
After the page loads and the browser has some data, you can send data back to php. This is not the same as your attempt though. You may need to rethink your strategy.