Reputation: 3
I have an array of records and I want to remove the duplicate record. I know we can use array_unique() to remove duplicate value but in my case I have an array of records like(Date, Url, xyz). I want to skip the date column while checking the duplicate record.
You can check my code bellow.
$array = array(
array('2014', 'http://example.com', 'xyz'),
array('2013', 'http://example.com', 'xyz'),
array('2010', 'http://example.com', 'xyz'),
array('2011', 'http://example.com', 'xyz'),
array('2019', 'http://example.com', 'xyz')
);
You can check that i have 5 same records just the date is different so I just need one record like
array('2019', 'http://example.com', 'xyz')
I hpoe you can understand. If you have anyother question please comment bellow Thanks!
Upvotes: 0
Views: 109
Reputation: 54
This code works for me please try this code.
$array = array(
array('2014', 'http://example.com', 'xyz'),
array('2013', 'http://example.com', 'xyz'),
array('2010', 'http://example.com', 'xyz'),
array('2011', 'http://example.com', 'xyz'),
array('2019', 'http://example.com', 'xyz')
);
$arr = array();
foreach ($array as $key => $item) {
$id = $item[0];
unset($item[0]);
$arr[$id] = $item;
}
$input = krsort($arr, SORT_NUMERIC);
echo '<pre>';
print_r(array_unique($arr));
Hope this will help you.
Upvotes: 3