When I run the query below I keep getting the values twice. The array holds [1,2,1,2] and it should hold only values [1,2]. Could someone explain to me why I get the duplicate values?
$grusnro = 0;
while (!empty($grus[$grusnro ]))
{
$catid="SELECT cat_id FROM catgroup WHERE group_id='$grus[$grusnro]'";
$catidsult=mysql_query($catid);
while($grunamerow = mysql_fetch_array($catidsult, MYSQL_ASSOC))
{
$catgroup[]=$grunamerow['cat_id'];
}
$grusnro = $grusnro +1;
}
When I run from command-line I get the result [1,2]. I have checked that the group_id values are only once in the $grus array. So why the duplicates?
array_unique. Now, if Emil solution works as you pointed out, can you accept his solution?