title: How to use foreach php code in registerJS() javascript code in yii2?
body: <p>I can't use foreach php code in javascript code of registerJS in yii2. Browser shows "PHP Parse Error – yii\base\ErrorException syntax error, unexpected 'foreach' (T_FOREACH)" error. Here is my code:</p>
  
  <pre><code>&lt;canvas id="bar-chart" width="500" height="150"&gt;&lt;/canvas&gt;
  
  &lt;?php 
  $lang = Yii::$app-&gt;language;
  $title = 'title_'.$lang;
  
  $this-&gt;registerJs("
                  new Chart(document.getElementById('bar-chart'), {
                  type: 'bar',
                  data: {
                    labels: [
                                  " . foreach ($models as $model) { . "
                                      ' " . $model-&gt;$title . " ',
                                 " . } . "
                             ],
                    datasets: [
                      {
                        label:'Label',
                        backgroundColor: ['#3e95cd', '#8e5ea2','#3cba9f', '#e7fc00'],
                        data: [479,1654,499, 2632]
                      }
                    ]
                  },
                  options: {
                    legend: { display: false },
                    title: {
                      display: true,
                      text: 'Title'
                    }
                  }
              });
      ", yii\web\View::POS_READY);
  </code></pre>