JavaScript = client side (in the browser)
PHP = server side
For a JavaScript value to get to something PHP can play with, you have to issue a post or get request with the necessary JavaScript data included. Without this, PHP has no way to know what JavaScript is doing.