$mp = array(
array('url'=>'www.abc.com','time'=>'1433551154','referral_url'=>'www.pqr.com'),
array('url'=>'www.xyz.com','time'=>'1433551150','referral_url'=>'www.stu.com'),
array('url'=>'www.lmn.com','time'=>'1433551190','referral_url'=>'www.jhi.com'),
array('url'=>'www.rst.com','time'=>'1433551170','referral_url'=>'www.pqr.com')
);
The above is the input array, I need output with sort by time and unique by referral_url.
Resultant will be-
$mp = array(
array('url'=>'www.lmn.com','time'=>'1433551190','referral_url'=>'www.jhi.com'),
array('url'=>'www.rst.com','time'=>'1433551170','referral_url'=>'www.pqr.com'),
array('url'=>'www.lmn.com','time'=>'1433551150','referral_url'=>'www.stu.com'),
);
Remember first sort by time then remove the duplicate by referral_url.
My Code, what i tried-
public function unique_sort($arrs, $id) {
$unique_arr = array();
foreach ($arrs AS $arr) {
if (!in_array($arr[$id], $unique_arr)) {
$unique_arr[] = $arr[$id];
}
}
sort($unique_arr);
return $unique_arr;
}
foreach($mp as $key => $row){
$referral_url[$key] = $row['referral_url'];
$time[$key] = $row['time'];
$url[$key] = $row['url'];
}
array_multisort($time, SORT_DESC, $mp);
$sort_arr = $this->unique_sort($mp, 'referral_url');
print_R($uniqueArray);exit;
But it only result me referral_url-
Array(
[0] => www.jhi.com
[1] => www.pqr.com
[2] => www.stu.com
)
i need all as above defined output.
Please suggest the way. Thanks in advance.