1

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:

  1. Is there a way to call the values as an associative?
  2. If there is(I'm sure I'm just doing something silly here), how do I identify the name of the variable?

Thanks!

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
b3tac0d3
  • 899
  • 1
  • 10
  • 15
  • 1
    http://php.net/manual/en/faq.html.php#faq.html.arrays and http://stackoverflow.com/questions/3314567/how-to-get-form-input-array-into-php-array might be a help – Kita Aug 31 '15 at 15:46
  • Thank you! That was exactly what I needed. Please post it as the answer and I'll definitely vote up! – b3tac0d3 Aug 31 '15 at 15:52
  • thank you, I've added my answer – Kita Aug 31 '15 at 16:04

2 Answers2

2

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

Community
  • 1
  • 1
Kita
  • 2,604
  • 19
  • 25
0

Try var_dump($_GET); You will see all variables.

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
Arturs Smirnovs
  • 163
  • 2
  • 6
  • 3
    Why should the OP "try this"? A good answer will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO. – Jay Blanchard Aug 31 '15 at 15:46
  • 1
    I have and I have verified that the variables are posting. It's just one variable that holds an on/off value. I should have posted this as well – b3tac0d3 Aug 31 '15 at 15:47