jexx;10933173 wrote:Thanks for the help 🙂
Could you explain how to do this ?
Thanks
Hes saying using an array is an easier way of outputting data effectively.
For example:
$tp[] = "data1";
$tp[] = "data2";
So now $tp is an array and looks like this:
Array
(
[0] => data1
[1] => data2
)
foreach ($tp as $key => $value) {
echo "$value\n";
}
//OUTPUTS
Data1
Data2
The foreach array loops twice, each time the array key and value are being assigned to $key and $value respectively, then the loop will echo the contents of $value to screen (on each loop being, data1 and data2).
If you want to add a new value to the array you just use the following:
$tp[] = "data3";
And now the array would have a third element and would look like this:
Array
(
[0] => data1
[1] => data2
[2] => data3
)
Now the foreach loop would run a third time and print "data3" as well. Just make sure you add all elements you want outputted before you run the foreach loop, otherwise it will not print all values because obviously they don't exist 😛
If from a form and you post all the data in one array, this is fine, but you would use $tp[] on the form data you want to post as its name and then use $_POST['tp'] var in the foreach loop on the action page 🙂