title: Undefined offset: 4
body: <p>I'm new in Yii programming and i found this notice when i try to make a quiz modul. !</p>
  
  <pre><code>Undefined offset: 4
  
  it indicates error in line 
  **if ($data-&gt;idjawab == $jawabanku[$x]) **
  </code></pre>
  
  <p>here's my _form.php code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form method="post"&gt;
  
      &lt;?php
          $x = 0;
          $static = array('null'  =&gt; 'Tidak Tahu'); //Opsi untuk jawaban kosong
          foreach ($soal as $data)
          {
              echo $data-&gt;soal."&lt;br&gt;";
  
              $list = CHtml::listData($data-&gt;jawabanjawabans, 'idjawab',  'jawaban');
              echo CHtml::radioButtonList("jawabanku[$x]", '', $list + $static);
              $x++;
              
              echo "&lt;br&gt;&lt;br&gt;&lt;hr&gt;";
          }
      ?&gt;
      
      &lt;div class="form-actions"&gt;
        &lt;div class="col-lg-3"&gt;
        &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
          &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
          &lt;button type="submit" class="btn btn-primary btn-lg" aria-label="Center"&gt;
          &lt;span class="glyphicon glyphicon-save" aria-hidden="true"&gt;&lt;/span&gt;
            Simpan
          &lt;/button&gt;
          &lt;br&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>here's my crate code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  $this-&gt;breadcrumbs=array(
   'Simulasis'=&gt;array('index'),
   'Create',
  );
  ?&gt;
  &lt;br&gt;
  
  &lt;div &gt;
              &lt;ol class="breadcrumb"&gt; 
                  &lt;li&gt;&lt;a href="&lt;?php echo Yii::app()-&gt;request-&gt;baseUrl; ?&gt;/site/index"&gt;Beranda&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;class="active"&gt;Simulasi&lt;/a&gt;&lt;/li&gt;
                  
              &lt;/ol&gt;
  
          &lt;/div&gt;
  
  &lt;div class="alert alert-dismissable alert-info"&gt;
            &lt;button type="button" class="close" data-dismiss="alert"&gt;×&lt;/button&gt;
            &lt;strong&gt;Penting!&lt;/strong&gt; Isikan masing-masing kolom jawaban dengan benar. &lt;br&gt;
            Jawaban benar akan mendapat poin +4. &lt;br&gt;
            Jawaban salah akan mendapatka poin -1. &lt;br&gt;
            Jawaban kosong akan mendapatkan poin 0. &lt;br&gt;
            Kerjakan dengan baik dan benar. Telitilah dalam membaca soal. Kerjakan &lt;b&gt;hanya soal yang yakin dapat dikerjakan&lt;/b&gt;
    &lt;/div&gt;
  
  &lt;div class="panel panel-primary"&gt;
    &lt;div class="panel-heading"&gt;
      &lt;h1 class="panel-title" &gt;Simulasi&lt;/h1&gt;
    &lt;/div&gt;  
    &lt;div class="panel-body"&gt;
  
   &lt;?php $this-&gt;renderPartial('_form', array('soal'=&gt;$soal)); ?&gt;
  
   &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and here's my controller</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> public function actionCreate()
   {
    $this-&gt;layout='//layouts/column_banksoal';
    if (isset($_POST['jawabanku'])) {
     $jawabanku = $_POST['jawabanku'];
     CVarDumper::dump($jawabanku,15,true);
     $jwbBenar = Soalsoal::model()-&gt;findAll(array(
      "select"=&gt;"idjawab",  
      "order"=&gt;"idsoalsoal ASC"));
     $benar = 0; $salah = 0; $kosong = 0; $totalskor=0; $jmlbenar=0; $jmlsalah=0;
     $x = 0;
     
     foreach ($jwbBenar as $data) { 
       if ($data-&gt;idjawab == $jawabanku[$x]) {
        $benar++;
       } else if ($jawabanku[$x] == 'null') {
        $kosong++;
       } else {
        $salah++;
       }
       $x++;
      
     }
     
     $jmlbenar = (4*$benar);
     $jmlsalah = ((-1)*$salah);
     $totalskor = $jmlbenar + $jmlsalah;
     //var_dump($totalskor,$jmlbenar,$jmlsalah);
     
     $this-&gt;render('hasil', array('benar'=&gt;$benar, 'kosong'=&gt;$kosong, 'salah'=&gt;$salah, 'totalskor'=&gt;$totalskor, 'jmlbenar'=&gt;$jmlbenar, 'jmlsalah'=&gt;$jmlsalah));
    } else {
     $idbidang=Yii::app()-&gt;user-&gt;idbidang;
     $soal = Soalsoal::model()-&gt;findAll(array(
      "select"=&gt;"idsoalsoal,soal,idbidang,gambar,kunci,idjawab", 
      "condition"=&gt;"idbidang=$idbidang", 
      "order"=&gt;"rand() LIMIT 40"));
     
     $this-&gt;render("create", array("soal"=&gt;$soal));
  
    }
  
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>i'm new in programming and i new in using yii framework too. If any of you know how to solve this please do. It is for my school task</p>