PHP:将自定义密钥对推送到数组中

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.

$emailFROM = imap_search($mbox, 'FROM "'.$address.'"', SE_UID);
$emailTO = imap_search($obox, 'TO "'.$address.'"', SE_UID);
$thread = array_merge($emailFROM, $emailTO);

So that's the array of all messages. It outputs like this:

Array
(
    [0] => 445
    [1] => 446
    [2] => 450
    [3] => 462
    [4] => 468
    [5] => 110
    [6] => 112
    [7] => 114
    [8] => 167
    [9] => 169
    [10] => 170
)

Unfortunately, the emailFROM numbers and the emailTO numbers do not line up (emailFROM are numbers 445-468, emailTO is 110-170)

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

This is what I have so far:

$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->date;
    $full_thread[$from]=$date;
}
//Then I will arrange the array when the array works
print_r($full_thread);

But I believe this doesn't work because it's looking for the $from id in the array first? So, I'm not sure where to go from here.

Thanks!

It would seem more poignant to define the array keys instead of performing a blind array_merge(). In this way, you can access and update the index on full_thread based on the index of the array item, for example:

$thread['from'] = $emailFROM;
$thread['to']   = $emailTO;

Now your foreach loop can keep a reference to the index.

foreach($thread as $type => $single){

Then you can change your array key definition on full_thread to your $type index.

    $full_thread[$type]['date'] = $date;

The extra ['date'] key is not required.