You really don't understand how this works.
Javascript is a client language, which means that it runs in a web browser. PHP is server-side, which means that it runs on the server.
When processing the request, the first PHP is executed, the response is returned to the user, and then Javacript is executed.
For communication between the client and the server, you can use ajax requests, which are basically simple HTTP requests, but without reloading the entire page.
source share