I am working with PHP and I have made this code: `
$categories = array('casual','dinner', 'kids');
$numberOfCategories = count($categories);
for ($i=0; $i < $numberOfCategories; $i++) {
$req = $pdo->query('
SELECT ProductID
, ProductCategoryID
FROM products
WHERE ProductCategoryID LIKE "%'.$categories[$i].'%"
');
while (${"relatedProduct" . $i} = $req->fetch()) {
var_dump(${"relatedProduct" . $i});
}
}
`
After running the code I got the following result:

If you look at it closely, you will notice that certain products repeat them self (which is normal).
What I want to do now his to combine the result of each loop stored in the variable ${"relatedProduct" . $i} and filter that result(result after combining the result of each loop) to avoid repetition of products based on the column ProductID
Kindly help me solve this problem.
ProductCategory (ProductId, Category)table and let DBMS do the job with proper query,ProductCategoryID, so I used the functionimplode()to separate the different elements of the array, so that they can be insert in the table