The function foreach() is only used when a variable is of type array. What is an array? It's a collection of related data. Say you have an array called $testscores.
The array data would look like this:
$testscores[0] = 95;
$testscores[1] = 86;
$testscores[2] = 58;
$testscores[3] = 87;
$testscores[4] = 78;
It could also look like this:
$testscores = array(95, 86, 58, 87, 78);
As for your form, the data you submit goes into an array called $_POST.
So if you had fields like: name, age, location -- Your array would look like this:
$POST["name"] = "name submitted";
$POST["age"] = 50;
$_POST["location"] = 'USA';
The foreach expression you would use in this case is:
foreach(array_expression as $key => $value) statement
The reason is that this array is an "associative array," meaning, instead of numbers as the key, expressions (like name, age.. ) are used instead.
Finally, your could to print out the data in the $POST array is this:
foreach($_POST as $k => $v) {
print "\$_POST[$k] => $v.\n";
}
*note: $HTTP_POST_VARS has been deprecated, which is why I used $_POST. Read the part about forms here for more details.
I hope this helped. 🙂