title: PHP: push custom key pair into array
body: <p>I am trying to get dates from emails using imap with PHP.  I've got my messages from my inbox and sent items, then I've merged them together, but now I need to put them into order by date sent.</p>
  
  <pre><code>$emailFROM = imap_search($mbox, 'FROM "'.$address.'"', SE_UID);
  $emailTO = imap_search($obox, 'TO "'.$address.'"', SE_UID);
  $thread = array_merge($emailFROM, $emailTO);
  </code></pre>
  
  <p>So that's the array of all messages.  It outputs like this: </p>
  
  <pre><code>Array
  (
      [0] =&gt; 445
      [1] =&gt; 446
      [2] =&gt; 450
      [3] =&gt; 462
      [4] =&gt; 468
      [5] =&gt; 110
      [6] =&gt; 112
      [7] =&gt; 114
      [8] =&gt; 167
      [9] =&gt; 169
      [10] =&gt; 170
  )
  </code></pre>
  
  <p>Unfortunately, the emailFROM numbers and the emailTO numbers do not line up (emailFROM are numbers 445-468, emailTO is 110-170)</p>
  
  <p>So now I need to go through each email and find the date, then I want to push the date into an array using the message ID number as the key</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>$emailFROM = imap_search($mbox, 'FROM "'.$address.'"', SE_UID);
  $emailTO = imap_search($obox, 'TO "'.$address.'"', SE_UID);
  $thread = array_merge($emailFROM, $emailTO);
  $full_thread = array();
  foreach($thread as $single){
      $header = imap_header($mbox, $single);
      $date = $header-&gt;date;
      $full_thread[$from]=$date;
  }
  //Then I will arrange the array when the array works
  print_r($full_thread);
  </code></pre>
  
  <p>But I believe this doesn't work because it's looking for the <code>$from</code> id in the array first?  So, I'm not sure where to go from here.</p>
  
  <p>Thanks!</p>