title: How to set the index value as 0 for the array in php?
body: <p>I am working on my php to fetch the data to store them in an array. I have got a problem with the index value in the array, because the index value will start with 1 then it will count it up to 2, 3, 4...etc which it should start with 0 then 1, 2 3...etc, because I am using <code>$i = 0;</code> to start with zero as default.</p>
  
  <p>Here is what I use that the index value start with 1:</p>
  
  <pre><code>if(isset($structure-&gt;parts) &amp;&amp; count($structure-&gt;parts)) {
  
      for($i = 0; $i &lt; count($structure-&gt;parts); $i++) {
  
          if (($structure-&gt;parts[$i]-&gt;ifdisposition) &amp;&amp; ($structure-&gt;parts[$i]-&gt;disposition == 'attachment')) {
  
              foreach($structure-&gt;parts[$i]-&gt;parameters as $object) {
                  if(strtolower($object-&gt;attribute) == 'name') {
                      $attachments[$i]['is_attachment'] = true;
                      $attachments[$i]['name'] = $object-&gt;value;
                      $attachments[$i]['attachment'] = '';
                  }
              }
          }
      }
  </code></pre>
  
  <p>I have tried to change from <code>$i++</code> to <code>$i</code> and I tried to put <code>$i++</code> in the for loop, but it didn't work.</p>
  
  <p>Output: </p>
  
  <pre><code>Array ( [1] =&gt; Array ( [is_attachment] =&gt; 1 [name] =&gt; 2019-01-23 (1).rar [attachment] =&gt; ) [2] =&gt; Array ( [is_attachment] =&gt; 1 [name] =&gt; email.zip [attachment] =&gt; ) )
  </code></pre>
  
  <p>It should be:</p>
  
  <pre><code>Array ( [0] =&gt; Array ( [is_attachment] =&gt; 1 [name] =&gt; 2019-01-23 (1).rar [attachment] =&gt; ) [1] =&gt; Array ( [is_attachment] =&gt; 1 [name] =&gt; email.zip [attachment] =&gt; ) )
  </code></pre>
  
  <p>Here is the full code:</p>
  
  <pre><code>&lt;?php
  
  require_once "Mail.php";
  require_once('Mail/IMAPv2.php');
  
  $username = 'username';
  $password = 'password';
  $mailserver = '{imap.domain.com:993/imap/ssl/novalidate-cert}INBOX';
  $mailbox = imap_open($mailserver, $username, $password) or die("Can't connect: " . imap_last_error());
  $key = "key";
  $email_number = openssl_decrypt(hex2bin('477'),'AES-128-CBC', $key);
  $attach_id = $_GET['attid'];
  
  /* get information specific to this email */
  $overview = imap_fetch_overview($mailbox, $email_number, 0);
  
  $message = imap_fetchbody($mailbox, $email_number, 2);
  
  /* get mail structure */
  $structure = imap_fetchstructure($mailbox, $email_number);
  $attachments = array();
  $attachment_number = 0;  
  
  if(isset($structure-&gt;parts) &amp;&amp; count($structure-&gt;parts)) {
  
      for($i = 0; $i &lt; count($structure-&gt;parts); $i++) {
  
          if (($structure-&gt;parts[$i]-&gt;ifdisposition) &amp;&amp; ($structure-&gt;parts[$i]-&gt;disposition == 'attachment')) {
  
              foreach($structure-&gt;parts[$i]-&gt;parameters as $object) {
                  if(strtolower($object-&gt;attribute) == 'name') {
                      $attachments[$i]['is_attachment'] = true;
                      $attachments[$i]['name'] = $object-&gt;value;
                      $attachments[$i]['attachment'] = '';
                  }
              }
          }
      }
      ?&gt;
  </code></pre>
  
  <p>I am unable to find out why the index value have always start with 1 when it should have start with zero then 1, 2, 3 as it get counting up the value each time.</p>
  
  <p>Can you please show me an example how I can start the index value with 0 as a default then count it up to 1, then 2, 3, 4, 5...etc when I am using <code>$i++</code>?</p>
  
  <p>Thank you.</p>