title: How to convert my PHP array to a Javascript array in laravel 4
body: <p>in my controller i have an array which i have populated from my database and stored which looks like this and is called dataset2</p>
  
  <pre><code>    array(2) {
        ["April"]=&gt; int(92)
        ["May"]=&gt;  int(86)
      }
  </code></pre>
  
  <p>In my view i can dd{{}} on the array and see this is the structure.</p>
  
  <p>Now I want to convert it into a javascript array so i can use flot to make it into a graph.</p>
  
  <p>my Javascript within my view looks like this</p>
  
  <pre><code> &lt;script language="javascript" type="text/javascript"&gt;
      $(function () {
  
          var data1 = [
              ["April", 13],
              ["May", 20],
           ];
  
     var data2 = [&lt;?php echo json_encode($dataset2 );?&gt;];
  
     $.plot("#placeholder", [{
         data: data1,
         label: "NewBeach"
     }, {
         data: data2,
         label: "Sandhills"
     }], {
         series: {
             lines: { show: true },
             points: {
                show: true,
                barWidth: 0.1,
                align: "center"
             }
         },
         xaxis: {
             mode: "categories"
         },
          yaxis: {
         },
         grid: { 
             hoverable: true, 
             clickable: true 
         }
     });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Am i missing something when converting it?, as it doesnt draw anything with the JSON_encode array but does with the hard coded one. From what i have read it seems as though thats all i need. Is it because of the values within my array?</p>
  
  <p>Kind regards
  Mike</p>