I have users in my site and the users choose their group 1/2/3 from their profile. Based on their choice they are grouped into 3 arrays:
$group1_recipients[], $group2_recipients[], $group3_recipients[]
Example data:
$group1_recipients = ["user A","user B","user C"],
$group2_recipients = ["user D","user B","user E"],
$group3_recipients = ["user A","user B","user E"]
This means User A has chosen Group1 and Group3. Similarly User B has chosen Group1,2 and 3.
Now, I am creating images and I choose Groups 1/2/3 while creating the images. So based on the users groups selection I want to show/hide an image:
Example: If i create an image for Group 1 and Group 2, only the users who have selected those groups can see the image. Also if a user has selected both Group1 and Group2 they should be able to see only 1 image. No duplicates.
I followed the below logic:
$groups = ["1", "2", "3"];
$match = false;
foreach ($groups as $g) {
if (in_array($g, $groups)) {
$match = true;
break;
}
}
if(true===$match)
{
if($g == "1"){
$audience = $group1_recipients;
}
else if($g == "2"){
$audience = $group2_recipients;
}
else if($g == "3"){
$audience = $group3_recipients;
}
}
else
{
echo "No matching audience type";
}
This logic doesn't fully work. When an image is created for all 3 groups and the user has selected only Group 2 or Group 3, the image is not showing. The logic leaves the loop as soon as one matching group is found. Any help on how this can be fixed?
PS: This is a sample code. Pls ignore parse/syntactic errors