I have the following array
at the moment:
array (size=3)
0 => string 'ketchup' (length=7)
1 => string 'mustard' (length=7)
2 => string 'barbecue' (length=8)
I would need to put a phrase like this:
You have chosen
ketchup
,mustard
,barbecue
.
However, the user who will insert what sauces he wants, he can for example choose only ketchup, or just mustard, or ketchup / mustard / barbecue / mayonnaise / pepper / sweet and sour, ie the array can have 1 item, or 2 items, or 3 items, or 4 items ... or 10 items, depends on the user.
What logic could I use to build the following structure?
Example: Ketchup, Mustard.
You have chosen
ketchup
,mustard
.
Example: Ketchup, Mustard, Barbecue, Mayonnaise, Pepper, Bittersweet.
You have chosen
ketchup
,mustard
,barbecue
,pimenta
,agridoce
.
I've thought of using something like this:
echo "Você escolheu $molhos[0], $molhos[1]."
But as I mentioned, you can only have 1 item in the array or 2 or 3 or 4 or even 10.
I also thought about foreach
, but I could not get any results.