I have a number of different options for distributing some records. The options are Word, Excel, PDF, and email.
According to the options checked on the back-end, the appropriate options will be available for sharing on the front-end. The problem is that I need to prepare a descriptive text as instructions for this matter. The text for the various cases, would be something like this:
You can download the selected records in Word, Excel, PDF, or send them to your email. (when all four options are enabled).
You can download the selected records in Word, PDF, or send them to your email. (when Word, PDF, and email options are enabled).
You can download the selected records in Word, or PDF. (when Word, and PDF options are enabled).
You can download the selected records in Word, or send them to your email. (when Word and email options are enabled).
You can send the selected records to your email. (when only the email is enabled).
There are other combinations also, but the tricky cases are when the email option is not enabled at all, or when only the email option is enabled. In all other cases, from what I can think of, all options except for the last one should be joined with ,, and the last with the previous ones with , or.
The order will always be the same when all for options are enabled: Word, Excel, PDF, Email.
Can someone attempt to produce an algorithm that would prepare the above descriptive text automatically without have to take all different combinations?
TIA.
Edit: How many different combinations can exist?
There are no tricks to talk about, just list all different branches. But it's only when you have many options that you can reduce the amount of code. https://3v4l.org/fYcMc