Advertisement
Guest User

Map of email threads PHP 5.5

a guest
Jul 9th, 2013
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Threads MAP
  5.  */
  6.  
  7. $threads = array(
  8.     5  => array(5,6),
  9.     10 => array(10,11),
  10. );
  11.  
  12. /**
  13.  * Emails list
  14.  */
  15.  
  16. $email5 = new stdClass;
  17. $email5->subject = 'Cloud Storage Dump';
  18. $email5->to = 'jondoe@domain.com';
  19. $email5->msgno = 5;
  20.  
  21. $email6 = new stdClass;
  22. $email6->subject = 'Cloud Storage Dump 6';
  23. $email6->to = 'jondoe@domain6.com';
  24. $email6->msgno = 6;
  25.  
  26. $email10 = new stdClass;
  27. $email10->subject = 'Cloud Storage Dump 10';
  28. $email10->to = 'jondoe@domain10.com';
  29. $email10->msgno = 10;
  30.  
  31. $email11 = new stdClass;
  32. $email11->subject = 'Cloud Storage Dump 11';
  33. $email11->to = 'jondoe@domain11.com';
  34. $email11->msgno = 11;
  35.  
  36. $emails = array($email5, $email6, $email10, $email11);
  37.  
  38.  
  39.  
  40. /**
  41.  * Create map of key-threads
  42.  */
  43.  
  44. function genetateKeyMap($emails)
  45. {
  46.     foreach($emails as $k => $email)
  47.     {
  48.         yield $email->msgno => $k;
  49.     }
  50. };
  51. $keys = iterator_to_array(genetateKeyMap($emails));
  52.  
  53.  
  54. /**
  55.  * Assign email details to thread map
  56.  */
  57.  
  58. function updateThreads($emails, $threads, $keys)
  59. {
  60.     foreach($threads as $thread)
  61.     {
  62.         $array = array();
  63.         foreach($thread as $msgno)
  64.         {
  65.             $array[] = $emails[$keys[$msgno]];
  66.         }
  67.         yield $array;
  68.     }
  69. };
  70. $threads = iterator_to_array(updateThreads($emails, $threads, $keys));
  71.  
  72.  
  73. echo '<br><hr><br /><pre>'. print_r($threads, true). '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement