I have an array data like this
Array
(
[0] => Array
(
[MACHINE] => A1
[LOT] => B1077
[slot] => 1
)
[1] => Array
(
[MACHINE] => A2
[LOT] => B0229
[slot] => 2
)
[2] => Array
(
[MACHINE] => A2
[LOT] => B0132
[slot] => 2
)
[3] => Array
(
[MACHINE] => A2
[LOT] => B3967
[slot] => 2
)
[4] => Array
(
[MACHINE] => A3
[LOT] => B2644
[slot] => 3
)
)
in array, the "machine" and "slot" have duplicate values. I want keep only one value of "machine" and "slot" then push "lot" value of duplicate "machine" and "slot" into it. The result I want like this:
Array
(
[0] => Array
(
[MACHINE] => A1
[LOT] => B1077
[slot] => 1
)
[1] => Array
(
[MACHINE] => A2
[LOT] => B0229
[slot] => 2
[Duplicate] => B0132, B3967
)
[2] => Array
(
[MACHINE] => A3
[LOT] => B2644
[slot] => 3
)
)
I have tried this to remove repeat value, but have no idea about how to get the result I want.
$temp = array();
foreach ($array as $v) {
if (!isset($temp[$v['MACHINE']]))
$temp[$v['MACHINE']] = $v;
}
$result = array_values($temp);
echo '<pre>', print_r($result, true), '</pre>';