Reputation: 908
I'm have 4 forms that I want to share the same action. When the PHP starts, I'm trying to get the value of my array before I run the code. The array name should represent the column name that I want to update and the value will be the column value. I've tried this echo $_GET[0];
but it doesn't return the value I'm looking for.
My question is twofold:
Thanks!
Upvotes: 1
Views: 2157
Reputation: 2634
To harness PHP's built-in support for automatic associative array generation directly from HTML FORM, here is a brief introduction:
http://php.net/manual/en/faq.html.php#faq.html.arrays
The following form will populate a multi-dimensional $_POST
.
<form method="POST">
<input name="words[]" value="...">
<input name="words[]" value="...">
<input name="foo[bar][]" value="...">
<input name="foo[bar][]" value="...">
<input name="foo[bar][]" value="...">
<input name="values[0][0][]" value="...">
<input name="values[0][0][]" value="...">
<input name="values[0][0][]" value="...">
</form>
$_POST
will be similar to
$_POST = [
"words" => [
0 => "...",
1 => "..."
],
"foo" => [
"bar" => [
0 => "...",
1 => "...",
2 => "..."
]
],
"values" => [
0 => [
0 => [
0 => "...",
1 => "...",
2 => "..."
]
]
]
];
Also, there is a related SO question that might be a help too:
How to get form input array into PHP array
Upvotes: 2