Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP: remove duplicate items in an array
- $items_thread = $connection -> fetch_all($sql);
- print_r($items_thread);
- Array
- (
- [0] => Array
- (
- [RecipientID] => 3
- [RecipientScreenname] => Tom L
- [RecipientFirstname] => Thomas
- [RecipientEmail] => info@xx.com
- )
- [1] => Array
- (
- [RecipientID] => 3
- [RecipientScreenname] => Tom L
- [RecipientFirstname] => Thomas
- [RecipientEmail] => info@xx.com
- )
- [2] => Array
- (
- [RecipientID] => 1
- [RecipientScreenname] => Lau T
- [RecipientFirstname] => TK
- [RecipientEmail] => lau@xx.co.uk
- )
- )
- print_r(array_unique($items_thread));
- Array
- (
- [0] => Array
- (
- [RecipientID] => 3
- [RecipientScreenname] => Tom L
- [RecipientFirstname] => Thomas
- [RecipientEmail] => info@xx.com
- )
- )
- Array
- (
- [0] => Array
- (
- [RecipientID] => 3
- [RecipientScreenname] => Tom L
- [RecipientFirstname] => Thomas
- [RecipientEmail] => info@xx.com
- )
- [1] => Array
- (
- [RecipientID] => 1
- [RecipientScreenname] => Lau T
- [RecipientFirstname] => TK
- [RecipientEmail] => lau@xx.co.uk
- )
- )
- $items_thread = array_unique($items_thread, SORT_REGULAR);
- $newArray = array();
- foreach ($origArray as $user)
- {
- $newArray[$user['RecipientID']] = $user;
- }
- $data = array_map('unserialize', array_unique(array_map('serialize', $data)));
- Array
- (
- [0] => Array
- (
- [RecipientID] => 3
- [RecipientScreenname] => Tom L
- [RecipientFirstname] => Thomas
- [RecipientEmail] => info@xx.com
- )
- [2] => Array
- (
- [RecipientID] => 1
- [RecipientScreenname] => Lau T
- [RecipientFirstname] => TK
- [RecipientEmail] => lau@xx.co.uk
- )
- )
Add Comment
Please, Sign In to add comment