Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Threads MAP
- */
- $threads = array(
- 5 => array(5,6),
- 10 => array(10,11),
- );
- /**
- * Emails list
- */
- $email5 = new stdClass;
- $email5->subject = 'Cloud Storage Dump';
- $email5->to = 'jondoe@domain.com';
- $email5->msgno = 5;
- $email6 = new stdClass;
- $email6->subject = 'Cloud Storage Dump 6';
- $email6->to = 'jondoe@domain6.com';
- $email6->msgno = 6;
- $email10 = new stdClass;
- $email10->subject = 'Cloud Storage Dump 10';
- $email10->to = 'jondoe@domain10.com';
- $email10->msgno = 10;
- $email11 = new stdClass;
- $email11->subject = 'Cloud Storage Dump 11';
- $email11->to = 'jondoe@domain11.com';
- $email11->msgno = 11;
- $emails = array($email5, $email6, $email10, $email11);
- /**
- * Create map of key-threads
- */
- function genetateKeyMap($emails)
- {
- foreach($emails as $k => $email)
- {
- yield $email->msgno => $k;
- }
- };
- $keys = iterator_to_array(genetateKeyMap($emails));
- /**
- * Assign email details to thread map
- */
- function updateThreads($emails, $threads, $keys)
- {
- foreach($threads as $thread)
- {
- $array = array();
- foreach($thread as $msgno)
- {
- $array[] = $emails[$keys[$msgno]];
- }
- yield $array;
- }
- };
- $threads = iterator_to_array(updateThreads($emails, $threads, $keys));
- echo '<br><hr><br /><pre>'. print_r($threads, true). '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement