title: Array to javascript
body: <p>I have an array of items from the database.</p>
  
  <pre><code>`$this-&gt;ingredientsHistory` is the variable that contains the array.
  </code></pre>
  
  <p>I want to convert this into a javascript var that will hold them all and I can then use them in the autocomplete jquery UI function.</p>
  
  <p>I've tried <code>var ingredients = &lt;?php echo json_encode($this-&gt;ingredientsHistory); ?&gt;</code> </p>
  
  <p>This is an example of a <code>print_r($this-&gt;ingredientsHistory);</code> output...</p>
  
  <blockquote>
    <p>Array ( [0] => Array ( [name] => oranges ) [1] => Array ( [name] => chicken ) )</p>
  </blockquote>
  
  <p>Any help would be appreciated.</p>
  
  <p>Edit - more information:</p>
  
  <pre><code>$(function() {
  var ingredients = &lt;?php echo json_encode($this-&gt;ingredientsHistory); ?&gt;;
  console.log(ingredients);
  //this is the default tags that jquery gives me - i need to turn ingredients into something similar.
  var availableTags = [
    "ActionScript",
    "AppleScript",
    "Asp",
    "BASIC",
    "C",
    "C++",
    "Clojure",
    "COBOL",
    "ColdFusion",
    "Erlang",
    "Fortran",
    "Groovy",
    "Haskell",
    "Java",
    "JavaScript",
    "Lisp",
    "Perl",
    "PHP",
    "Python",
    "Ruby",
    "Scala",
    "Scheme"
  ];
  $( "#tags" ).autocomplete({
    source: ingredients
  });
  </code></pre>
  
  <p>});</p>