Hi im a beginner in php i would like to ask how do i remove duplicates from multidimensional array and also keeping the array format. $nodecontainer4 is the array that i want to remove duplicates from.
Ive tried using this method but it still messes up the format after i JSON_ENCODE IT $input = array_map("unserialize", array_unique(array_map("serialize", $input)));
while($row =mysqli_fetch_assoc($result))
{
$nodecontainer {"id"} = ($row ["lefty"]);
$nodecontainer2 {"id"} = ($row ["righty"]);
$nodecontainer3 {"group"} = 1;
$nodecontainer6 {"group"} = 2;
$nodecontainer4 = array_merge($nodecontainer, $nodecontainer6);
$nodecontainer5 = array_merge($nodecontainer2, $nodecontainer3);
array_push($emparray, $nodecontainer4, $nodecontainer5);
}
This is how $nodecontainer4 looks like i want to remove the duplicates but still keeping the same format with the "id" and "group".
Array ( [id] => financial services [group] => 1 )
Array ( [id] => marketing[group] => 1 )
Array ( [id] => marketing [group] => 1 )
Array ( [id] => sales [group] => 1 )
Array ( [id] => sales [group] => 1 )
Array ( [id] => sales [group] => 1 )
Array ( [id] => sales [group] => 1 )
So the result i want to get back would look like
Array ( [id] => financial services [group] => 1 )
Array ( [id] => marketing [group] => 1 )
Array ( [id] => sales [group] => 1 )
Ive tried using this method but it still messes up the format after i JSON_ENCODE my array.
$input = array_map("unserialize", array_unique(array_map("serialize", $input)));