title: Pass php object to a javascript function
body: <p>I was wandering if it is possible to send a php object/array from a database into a javascript function through html?</p>
  
  <p>Here is what I am trying to accomplish:</p>
  
  <pre><code>&lt;?php
  $test = array('Apple', 'Banana', 'Lemon');
  ?&gt;
  
  &lt;a href="javascript:;" onclick="myfuntion(&lt;?php echo json_encode($test) ?&gt;);"&gt;Send object&lt;/a&gt;
  
  &lt;script type="text/javascript"&gt;
  function myfuntion(test)
  {
      console.log("What is first fruit: "+test[0]);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I get this error in my console:</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected end of input
  myfuntion([
  </code></pre>
  
  <p>What am I missing? Hoping for help and thanks in advance :-)</p>