You cannot do this directly, because JavaScript works on the client side, and PHP runs on the server side.
First you need to execute JavaScript, and then send the result to the server using a FORM or AJAX call.
Here's what it might look like:
Php
$parameter = "this is a php variable"; echo "var myval = foo(" . parameter . ");";
Javascript
var myval = foo("this is a php variable"); // generated by PHP $.ajax({ type: 'POST', url: 'yourphpfile.php', data: {'variable': myval}, });
Getting PHP (yourphpfile.php)
$myval = $_POST['variable']; // do something
source share