title: PHP array data used in javascript graph - codeigniter
body: <p>I am using API data in a model which is passed through to a controller then to view. In one particular instance I need to do a foreach() loop but in javascript to get the data I need, please see below how I've done it.</p>
  
  <p>I know this is bad practice but wanted to know what the best practice is to achieve this so I know going forward.</p>
  
  <pre><code>categories: [&lt;?php foreach($champ_name as $champ_id =&gt; $stat_value) {
                 foreach ($stat_value as $cn =&gt; $cs) {
                     if($champ_id != 0) {
                         echo '"'.$cn.'",';
                     }
                 } 
              } ?&gt;]
  </code></pre>
  
  <p>Thanks for looking/helping.</p>
  
  <p>(PS. the above does work but I know is not the right way)</p>