title: json_encode() works for one string but not another?
body: <p>EDIT:</p>
  
  <p>Solved. Somebody commented with an answer, but then deleted it. Embarrassingly, the problem was fixed by adding semi-colons after the two json_encode lines. I still have no idea why string1 worked without a closing semi-colon and string2 did not, but it works, so… success?</p>
  
  <p>/EDIT</p>
  
  <p>Hi… fairly nooby programmer here.</p>
  
  <p>Within PHP, I'm grabbing two arrays from my database. This works fine. I then implode each array into a string. This too works fine.</p>
  
  <p>Later in the same file, in the javascript section of my code (featuring jQuery), I do:</p>
  
  <pre><code>string1 = &lt;?php echo json_encode($string_1);?&gt;
  string2 = &lt;?php echo json_encode($string_2);?&gt;
  </code></pre>
  
  <p>Encoding string1 works perfectly… so long as I comment out the string2 line entirely. It kills my page.</p>
  
  <p>I've tried ensuring that my string is utf8-encoded. I've tried ensuring that there are no backslashes or other problematic characters. Currently, I've got some dummy code that's designed to be as unproblematic as possible… still doesn't work.</p>
  
  <p>Here's the skeleton version of it.</p>
  
  <p>PHP:</p>
  
  <pre><code>$array1 = array();
  $array2 = array();
  
  
  $i = 1;
  while($row = mysqli_fetch_assoc($query_result)) {
     $array1[$i] = $row['column1'];
     $array2[$i] = $row['column2'];
     $i++;
  }
  
  $string1 = implode(",", $array1);
  $string2 = "oh_come_on_why_doesnt_this_work"; // implode(",", $array2);
  </code></pre>
  
  <p>And JS/HTML/JQuery:</p>
  
  <pre><code>var string1;
  var string2;
  
  $.getScript("js/set_functions.js", function(){ loadedScript() });
  
  function loadedScript() {
  
      string1 = &lt;?php echo json_encode($string1);?&gt;
      string2 = &lt;?php echo json_encode($string2);?&gt;
      // string2 = &lt;?php echo "'" . $string2 . "'";?&gt; doesn't work either
  
      alert(string1); // works if I comment out both string2 = … lines
      alert(string2); // displays "undefined" if the first string2 = … line is commented…
      // …out, doesn't display at all if it isn't
  
  }
  </code></pre>
  
  <p>STUCK PLEASE HELP.</p>
  
  <p>Let me know if you need to see more of my code, or if there's anything else I could do to help make this question better. Thanks.</p>
  
  <p>PS: I'm not a good programmer, I know. Please don't correct my other bad coding habits IN LIEU OF helping solve this problem. Thanks!</p>
  
  <p>EDIT: Sorry, in response to Joe Fraumbach, that was an error in my copy-pasting. I had actually declared $array2 = array();</p>