You can use foreach() to iterate through ANY array. The important thing is knowing which values amount to arrays. $_POST is an array, as is the result of a call to mysql_fetch_array(). Keep in mind that if you have a multi-dimensional array, you need multiple foreach() statements.
For example, if you used an array in your html form to store checkbox values, i.e. -
<input type="checkbox" name="names[]" value="Jeff Smith">
<input type="checkbox" name="names[]" value="John Smith">
<input type="checkbox" name="names[]" value="Mike Smith">
Then you'll need to iterate not only $POST[], but the sub-array $POST['names']. What I prefer to do is simply use the extract() function, which automatically creates variables based on key names which contain their related values.
So the processing page for the HTML above would read:
extract($_POST);
$namelist = "";
foreach($namelist as $value)
{
$namelist .= "$value, ";
}
$namelist = substr($namelist, 0, -2);
echo $namelist;
// Would echo: Jeff Smith, John Smith, Mike Smith
Or better yet - when converting array values to a list, use implode()...
extract($_POST);
$namelist = implode(", ", $names);
echo $namelist;
// Would echo: Jeff Smith, John Smith, Mike Smith