I don't know what Rafiki is talking about; your use of a PHP variable inside double quotes is perfectly acceptable.
However, I can guess that the reason it only works without a space is because you're not being very kind to browsers; some browsers might work out that you're trying to give 'onclick' the value returned by the function select(), so they might parse until the closing bracket, but honestly if I was writing a browser I wouldn't try to compensate for that sort of laziness, and apparently neither is the browser you're testing in -- it's being charitable enough by assuming that the string is delimited by spaces, as such the value of 'onclick' becomes "select('ALL'," -- so it breaks.
You're supposed to encapsulate string values in quotes in HTML so you're going to have to do it properly;
$list = "contacts";
echo "<a href='#' onclick=\"select('ALL', '$list')\">Select All</a>";
# result: <a href='#' onclick="select('ALL', 'contacts')">Select All</a>
That should parse just fine on any browser.
If you don't like having to escape the quotes then you're better off using PHP as the templating engine it was designed to be;
<a href="#" onclick="select('ALL', '<?=$list;?>')">Select All</a>