undefined offset 0 PHP
<p>I uploaded an excel file which store into an array $allDataInSheet and try to print_r it in the view. This is the result :</p>

<pre><code>Array ([0] =&gt; 15220) Array ([0] =&gt; 15224)
</code></pre>

<p>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>$file_data = $this-&gt;upload-&gt;data();
                $file_path =  FCPATH.'kirim_undangan/';
                require_once APPPATH  .'third_party/PHPExcel.php';
               require_once APPPATH  .'third_party/PHPExcel/IOFactory.php';
    

                $inputFileName = $file_path; 
                $inputFileName;
                $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
                $allDataInSheet = $objPHPExcel-&gt;getActiveSheet()-&gt;toArray(null,true,true,true);
                $arrayCount = count($allDataInSheet);  // Here get total count of row in that Excel sheet
                $regex = "~\d{5}~";
                $dataexcel = Array();
               for($i=1;$i&lt;=$arrayCount;$i++)
               {

                    $dataexcel['to_name']=$allDataInSheet[$i]["A"];
                    $dataexcel['to_address']=$allDataInSheet[$i]["B"];
                    $dataexcel['to_phone']=$allDataInSheet[$i]["C"];
                    preg_match($regex, $allDataInSheet[$i]["B"], $result);
     $dataexcel['to_zipcode'] = $result;
                } 

   $data_user = array(

    'request_Id'     =&gt; $this-&gt;input-&gt;post('id'),
    'email'        =&gt; $this-&gt;input-&gt;post('email'),
    'name'            =&gt; $this-&gt;input-&gt;post('from_nama'),
    'phone'        =&gt; $this-&gt;input-&gt;post('from_phone'),
    'status'                =&gt; '0',
    'unique_id'            =&gt; uniqid()


       );


            $this-&gt;load-&gt;model('excel');
            $this-&gt;excel-&gt;tambahuser($allDataInSheet,$data_user);</code></pre>
</div>
</div>
</p>

<p>my model :</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>function tambahuser($allDataInSheet,$data_user)
    {
        $regex = "~\d{5}~";
        $this-&gt;db-&gt;insert('request', $data_user);
        $request_id = $this-&gt;db-&gt;insert_id();

        foreach ($allDataInSheet as $key)     
        {
            preg_match($regex, $key['B'], $result);       

            $data = array(
                'request_id'         =&gt;   $request_id,
                'from_name'          =&gt;   $this-&gt;input-&gt;post('from_nama'),
                'from_phone'         =&gt;   $this-&gt;input-&gt;post('from_phone'),
                //'from_address'       =&gt;   $this-&gt;input-&gt;post('from_address'),
                'to_name'           =&gt; $key['A'],
                'to_phone'          =&gt; $key['C'],
                'to_address'        =&gt; $key['B'],
                'to_zipcode'        =&gt; $result[0], //this is where the error comes
                'tariff'            =&gt; '0',
            );
            print_r($result);
            $this-&gt;db-&gt;insert('excel', $data);
        }</code></pre>
</div>
</div>
</p>

<p>But I get <code>Undefined Offset = 0</code>. </p>

<p>What did I do wrong ? cause the [0] Array is not NULL;</p>