Try this:
$product1 = "Hello";
$product2 = " my";
$product3 = " name";
$product4 = " is";
$product5 = " pete.";
$i=1; //assuming $product1 is the start
while(${product.$i})
{
echo ${product.$i};
$i++;
}
This might be more helpful for helping you understand the very flexible nature of variables used in php, although it should be a solution to your problem as well.
You can have any number of variables called $productN, but they have all follow that naming convention. The example makes is dynamically creating a variable name, and is assuming that the names will be in order. When there ceases to be a $productN, the loop will exit.
Let me know if this helps. If not, we'll figure something else out.
-pete
Bruno wrote:
I have something like
$product1, $product2, $product3, etc... $productN
where "N" varies according to the selection made before.
I'd like to know whether this is possible to create an array
containing all the $product (being aware that "N" is not a fixed value but is known),
so that I can then loop through all the values of all the $product.
Basically, I'd like to be able to make a loop that looks like:
foreach ($product ...) { //So here, $product1, $product2 until $productN would be considered one by one.
Thanks in advance!
Bruno