Guest User

Untitled

a guest
Sep 6th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. PHP: remove duplicate items in an array
  2. $items_thread = $connection -> fetch_all($sql);
  3.  
  4. print_r($items_thread);
  5.  
  6. Array
  7. (
  8. [0] => Array
  9. (
  10. [RecipientID] => 3
  11. [RecipientScreenname] => Tom L
  12. [RecipientFirstname] => Thomas
  13. [RecipientEmail] => info@xx.com
  14. )
  15.  
  16. [1] => Array
  17. (
  18. [RecipientID] => 3
  19. [RecipientScreenname] => Tom L
  20. [RecipientFirstname] => Thomas
  21. [RecipientEmail] => info@xx.com
  22. )
  23.  
  24. [2] => Array
  25. (
  26. [RecipientID] => 1
  27. [RecipientScreenname] => Lau T
  28. [RecipientFirstname] => TK
  29. [RecipientEmail] => lau@xx.co.uk
  30. )
  31.  
  32. )
  33.  
  34. print_r(array_unique($items_thread));
  35.  
  36. Array
  37. (
  38. [0] => Array
  39. (
  40. [RecipientID] => 3
  41. [RecipientScreenname] => Tom L
  42. [RecipientFirstname] => Thomas
  43. [RecipientEmail] => info@xx.com
  44. )
  45.  
  46. )
  47.  
  48. Array
  49. (
  50. [0] => Array
  51. (
  52. [RecipientID] => 3
  53. [RecipientScreenname] => Tom L
  54. [RecipientFirstname] => Thomas
  55. [RecipientEmail] => info@xx.com
  56. )
  57.  
  58. [1] => Array
  59. (
  60. [RecipientID] => 1
  61. [RecipientScreenname] => Lau T
  62. [RecipientFirstname] => TK
  63. [RecipientEmail] => lau@xx.co.uk
  64. )
  65.  
  66. )
  67.  
  68. $items_thread = array_unique($items_thread, SORT_REGULAR);
  69.  
  70. $newArray = array();
  71. foreach ($origArray as $user)
  72. {
  73. $newArray[$user['RecipientID']] = $user;
  74. }
  75.  
  76. $data = array_map('unserialize', array_unique(array_map('serialize', $data)));
  77.  
  78. Array
  79. (
  80. [0] => Array
  81. (
  82. [RecipientID] => 3
  83. [RecipientScreenname] => Tom L
  84. [RecipientFirstname] => Thomas
  85. [RecipientEmail] => info@xx.com
  86. )
  87.  
  88. [2] => Array
  89. (
  90. [RecipientID] => 1
  91. [RecipientScreenname] => Lau T
  92. [RecipientFirstname] => TK
  93. [RecipientEmail] => lau@xx.co.uk
  94. )
  95. )
Add Comment
Please, Sign In to add comment