The following script will remove duplicates from an array based on a single key. I found it via the following reference. Reference: remove duplicates from array (array unic by key)
The problem I have it that the $initial_data array may contain items with the same [Post_Date] values but different [Item_Title] values.
Is there a way to modify the code such that it only removes duplicates if both the [Post_Date] and [Item_Title] values are identicle?
// Remove Duplicates based on 'Post_Date'
$_data = array();
foreach ($initial_data as $v) {
if (isset($_data[$v['Post_Date']])) {
continue;
}
$_data[$v['Post_Date']] = $v;
}
// if you need a zero-based array, otherwise work with $_data
$unique_results = array_values($_data);
Below is a simplified output of the arrays showing 4 fields. The original arrays contain 16 fields.
$initial_data: Original Data Array. The [Post_Date] values are the same but the [Item_Title] values are different.
Array
(
[0] => Array
(
[id] => 22000
[Category] => vehicles
[Post_Date] => 1356373690
[Item_Title] => Car Painting
)
[1] => Array
(
[id] => 22102
[Category] => vehicles
[Post_Date] => 1356373690
[Item_Title] => Car Repair
)
...
)
$_data: The $_data array from within the script
Array
(
[1356373690] => Array
(
[id] => 22000
[Category] => vehicles
[Post_Date] => 1356373690
[Item_Title] => Car Painting
)
[1356373690] => Array
(
[id] => 22102
[Category] => vehicles
[Post_Date] => 1356373690
[Item_Title] => Car Repair
)
...
)
$unique_results: The final unique results array. As you can see the duplicate array item was removed by the script based on the [Post_Date] alone, but I need it to also evaluate if the [Item_Title] values are different or identical so that it will not consider this array item a duplicate.
Array
(
[0] => Array
(
[id] => 22000
[Category] => vehicles
[Post_Date] => 1356373690
[Item_Title] => Car Painting
)
...
)