title: how to make index at foreach and make it as json?
body: <p>I want to save my data from foreach as "name data": value to variable ChartVal, but I don't how to do it I'm still learning.   </p>
  
  <pre><code>  &lt;?php 
          $nim = $this-&gt;uri-&gt;segment(3);
          $chart = $this-&gt;modelpenilaian-&gt;getchart($nim);
          foreach ($chart as $ca) {
              $a[i] = "$ca-&gt;name": $ca-&gt;nilai;
          } //I know this is wrong, I just don't know the right one
  
  
  
      ?&gt;
      &lt;script&gt;
         var chartVals = &lt;?php echo json_encode($a[i])?&gt;;
      //I want to save to variable chartVals
  
      $(function(){
        $('#chart').radarChart({
          size: [500, 400],
          step: 1,
          title: " ",
          values: {
            //"chartVals": chartVals
            //then send it to jquery value
            chartVals
          },
          showAxisLabels: true
        });
      });
  </code></pre>