getting an array out of the POST array
| From: | Ian M. Evans | Date: | Tue, 17 Aug 2004 21:34:45 +0000 |
| Subject: | getting an array out of the POST array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-194093@lists.php.net to get a copy of this message | ||
One day I need to take a vacation with a big pot of coffee and study arrays. They're
my downfall.
We're moving to a new server and finally have a recent version of PHP.
We have a page on the site for captioning the photos with the names of the subjects.
After the form is posted, the script would do a bunch of things on the names, then
insert them:
while (list ($key, $val) = each ($firstname)) {
$firstname[$key] = trim($firstname[$key]);
$middlename[$key] = trim($middlename[$key]);
$lastname[$key] = trim($lastname[$key]);
...etc...
Now that we have a newer version of PHP, we have the $_POST variables, so the
$firstname $middlename $lastname arrays are tossed into the $_POST array.
I figured that it would change the above to:
while (list ($key, $val) = each ($_POST[firstname])){
$_POST[firstname][$key] = trim($_POST[firstname][$key]);
$_POST[middlename][$key] = trim($_POST[middlename][$key]);
$_POST[lastname][$key] = trim($_POST[lastname][$key]);
When I inserted that into the database I, of course ended up with the name:
"Array[0] Array[0] Array[0]"
How the heck do I get the name arrays out of the $_POST arrays?
Many thanks.