Advertisement
Guest User

Map of email threads

a guest
Jul 9th, 2013
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 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. $keys = array();
  45. foreach($emails as $k => $email)
  46. {
  47.     $keys[$email->msgno] = $k;
  48. }
  49.  
  50. /**
  51.  * Assign email details to thread map
  52.  */
  53. $threads = array_map(function($thread) use($emails, $keys)
  54. {
  55.     $thread = array_map(function($msgno) use($emails, $keys)
  56.     {      
  57.         return $emails[$keys[$msgno]];
  58.  
  59.     }, $thread);
  60.     return $thread;
  61.  
  62. }, $threads);
  63.  
  64.  
  65. echo '<br><hr><br /><pre>'. print_r($threads, true). '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement