select
user_id, count(*) as count, group_concat(product_id) as products
from wishlist
group by user_id;
function combinations($words)
{
if (count($words) == 1) {
return [$words];
};
$combinations = [];
$i = 0;
do {
$first_word = array_shift($words);
foreach (combinations($words) as $cmb) {
$combinations[] = array_merge([$first_word], $cmb);
};
array_push($words, $first_word);
} while (++$i < count($words));
return $combinations;
};
$combinations = combinations(explode(' ', 'word1 word2 word3 word4'));
print_r($combinations);