I just tried it. So, what happens is this: The PHP parser only cares what's inside the <? ?>tags, nothing else. So it sees this:
echo my_function('+myVar+','+1+');
The function is called with two Parameters, both strings: +myVar+ and +1+. You can check that by putting this in your function:
function my_function() {
$argv = func_get_args();
var_dump($argv);
}
It will output this:
array(2) {
[0]=>
string(7) "+myVar+"
[1]=>
string(3) "+1+"
}
After the PHP generated file is served the client sees this:
$(function() {
var myVar = 1;
$('#myDiv').html('The output of your my_function()');
});
Your JavaScript variable now isn't used anymore.
If you want to print content with a already known ID you can either define the variable in PHP or use a $_GET or $_POST variable to set it in PHP.
If you want to use a dynamic value you will need an AJAX call to another file (where you will have to do what I suggested above).
Mixing PHP and JavaScript like you did is just not possible.
myVarvalue in PHP.my_function()code.