This problem just slapped my face that I wasn't a great developer as much as I thought I was :) I cannot figure it out how to solve it. I'm assuming there should be a recursive function to do this but I'm open to any ideas.
Basically I have an array which is generated from user input.
$answers = [
'city' => ["Los Angeles", "San Diego", "Hollywood"],
'make' => ["Ferrari", "Bugatti", "Lamborghini"],
];
And another array that's associated with "city" and "make" answers.
$template = [
["Campaign L", "Best [make] in [city]", "Active"],
["Campaign O", "Cheap [make] in [city]", "Pause"],
["Campaign V", "Top [make] in [city]", "Active"],
["Campaign E", "[make] [city]", "Pause"],
["Campaign C", "Buy Now [make] in [city]", "Active"],
["Campaign A", "Sale [make] [city]", "Active"],
["Campaign R", "Fast [make] in [city]", "Active"],
["Campaign S", "Red [make] [city]", "Active"],
];
What I'm trying to do is to create a final output where I replace each answers in the template and generate a main output. I have a function to replace the tags so I'm not worried about that part however I cannot figure out how to loop through each combination.
There should be combination of each city and make so my final output should be like this:
$finalOutput = [
["Campaign L", "Best Ferarri in Los Angeles", "Active"],
["Campaign O", "Cheap Ferarri in Los Angeles", "Pause"],
["Campaign V", "Top Ferarri in Los Angeles", "Active"],
["Campaign E", "Ferarri Los Angeles", "Pause"],
["Campaign C", "Buy Now Ferarri in Los Angeles", "Active"],
["Campaign A", "Sale Ferarri Los Angeles", "Active"],
["Campaign R", "Fast Ferarri in Los Angeles", "Active"],
["Campaign S", "Red Ferarri Los Angeles", "Active"],
["Campaign L", "Best Bugatti in Los Angeles", "Active"],
["Campaign O", "Cheap Bugatti in Los Angeles", "Pause"],
["Campaign V", "Top Bugatti in Los Angeles", "Active"],
["Campaign E", "Bugatti Los Angeles", "Pause"],
["Campaign C", "Buy Now Bugatti in Los Angeles", "Active"],
["Campaign A", "Sale Bugatti Los Angeles", "Active"],
["Campaign R", "Fast Bugatti in Los Angeles", "Active"],
["Campaign S", "Red Bugatti Los Angeles", "Active"],
...
...
...
...
and goes on with other combinations...
];
I'm looking for a solution where it should also work when there are three items in the answer array (ex: [make] [model] [city]). How can I achieve this? Any ideas appreciated!
Thanks