Hi please help me to do find duplicate values and combine values in an array. i checked with the
array_map("unserialize",array_unique(array_map("serialize", $outer_array)));
but this is not actually I need . my requirement is
I have an array like this
INPUT
Array(
[0] => Array
(
[id] => 1
[latitude] => 12.9614126
[longitude] => 77.5610838
[type] => signature
)
[1] => Array
(
[id] => 2
[latitude] => 12.9614126
[longitude] => 77.5610838
[type] => customer
)
[2] => Array
(
[id] => 2
[latitude] => 12.9614126
[longitude] => 77.5610838
[type] => signature
)
[3] => Array
(
[id] => 2
[latitude] => 12.9614126
[longitude] => 77.5610838
[type] => signature
)
)
In the above array the key 1 and 2 contains same value for (id,latitude,longitude) but it different for type. and one more thing is the type contain duplicated that also need to remove
Here my expected result
OUTPUT
Array(
[0] => Array
(
[id] => 1
[latitude] => 12.9614126
[longitude] => 77.5610838
[type] => signature
)
[1] => Array
(
[id] => 2
[latitude] => 12.9614126
[longitude] => 77.5610838
Array
(
[0]=> Array(
[type] => customer
)
[1]=> Array(
[type] => signature
)
)
)
)
I tried this
$outer_array = array();
$unique_array = array();
foreach($arraydata as $image){
$inner_array = array();
$fid_value = $image['id'];
if(!in_array($image['id'], $unique_array))
{
array_push($unique_array, $fid_value);
array_push($inner_array, $image);
$outer_array[$fid_value] = $inner_array;
}else{
array_push($outer_array[$fid_value], $image);
}
}