I’ve got the current array
array
161 =>
array
'cat_id' => string '5' (length=1)
'temp_id' => string '2' (length=1)
'prod_id' => string '44' (length=2)
162 =>
array
'cat_id' => string '3' (length=1)
'temp_id' => string '2' (length=1)
'prod_id' => string '44' (length=2)
164 =>
array
'cat_id' => string '2' (length=1)
'temp_id' => string '2' (lenth=1)
'prod_id' => string '45' (length=2)
I am using this function to remove the duplicate array values:
function removeDupes($array) {
$temp = array();
foreach ($array as $k => &$v) {
if (in_array($v['prod_id'],$temp)) {
unset($array[$k]);
}
$temp[] = $v['prod_id'];
}
return $array;
}
This removes any duplicate value in the array if prod_id is a duplicate in a previous array.
I’d like to maintain the full category id list for the product and at the moment, these get deleted when I unset the entire key=>value pair.
Has anyone got any ideas how I could achieve this?
EDIT as per comment:
I’m looking for something like this as a result:
array
161 =>
'cat_id' => array('5','3')
'prod_id' => 44
So I have removed the duplicate array entry that duplicated the product ID but maintained the Category ID’s. I hope that helps.
Maybe something like this: