First of all this is not a duplicate as i haven't found any info about this. We can successfully remove duplicate values using the following from an array for example:
$messages= Array (
[0] => Array ( [user] => 2224 [sending_time] => 1536513903 [read_time] => 1536513941 [content] => sad [recipient_status] => read )
[1] => Array ( [user] => 3310 [sending_time] => 1536513903 [read_time] => 1536513941 [content] => sad [recipient_status] => read )
[2] => Array ( [user] => user1 [sending_time] => 1536513874 [read_time] => 1536567672 [content] => def [recipient_status] => read )
[3] => Array ( [user] => user1 [sending_time] => 1536513532 [read_time] => 1536513745 [content] => abc [recipient_status] => read )
)
Using the following i can remove the duplicates(by key):
$MSGS_array = array();
foreach ($messages as $message) {
$MSGS_array[$message['user']] = $message;
}
But the question is how can i get the removed user key value?
OR
How can i get all the duplicates having key user and their value(s) in an array from the array above?
Expected Output:
The output should only contain the removed/duplicates Like:(i just need the duplicates with they key user)
$output= Array (
[0] => Array ( [user] => user1 )
[1] => Array ( [user] => user1 )
);
OR
$output= Array (
[0] => Array ( [user] => user1 [sending_time] => 1536513874 [read_time] => 1536567672 [content] => def [recipient_status] => read )
[1] => Array ( [user] => user1 [sending_time] => 1536513532 [read_time] => 1536513745 [content] => abc [recipient_status] => read )
);