As Allen demonstrates: yes it is possible to use PHP vars in javascript,
because javascript is simply printed-text that get's executed by the browser after the php script has finished.
So all you have to do is get PHP to print the correct values into the script.
But... it's more difficult if you want to use a var in php, then pass the var to javascript and later pass the var from javascript back to php.