Well,
the object of that code is just to build the hidden inputs. If you have 10 textfields looking like this;
<input type="text" name="firstname" value="">
<input type="text" name="surname" value="">
...
And then submit these values to a new php-file (or the same one), you want to bring these variables on to the next page. So, list them all up in one single variable (only the fieldnames);
$fields = "firstname surname email phone";
(add all the ones you want to bring along). Now, explode this text string on ' ', and build a set of hidden inputs from them.
foreach (explode(' ', $fields) AS $key => $val) {
// Now we are working with a single 'word' from the $fields variable.
print '<input type="hidden" name="'.$val.'" value="'.$$val.'">';
}
So for each word in the $fields, this will output the text;
<input type="hidden" name="fieldname" value="(value of $fieldname)">
In other words,
step1.php
<form action="step2.php">
<input type="text" name="firstname" value="">
<input type="text" name="lastname" value="">
<!-- add submit button -->
</form>
step2.php
<form action="step3.php">
<input type="text" name="email" value="">
<input type="text" name="phone" value="">
<?php
// Bring along values from step1.php
$fields = "firstname lastname";
foreach (explode(' ', $fields) AS $key => $val)
print '<input type="hidden" name="'.$val.'" value="'.$$val.'">';
?>
<!-- add submit button -->
</form>
step3.php
<!-- add form & new fields -->
$fields = "firstname lastname email phone";
<!-- add foreach explode code from above -->
Hope that helped 😛