If I understand correctly, you want to put the Javascript string in your question into a PHP variable. This would look like this:
$myVar = "$('[id=\"a\"][f-id=\"0\"]').val($a)";
The backslashes () before the double quotes are escape characters that let PHP know that you want the actual character " to be in the string, otherwise PHP thinks you want to end the string.
Note that the $a doesn't need to be echoed in this context, because you're not outputting $a, but rather including it in a string.