0

If I had

<input type="text" name="myArray[0]">
<input type="text" name="myArray[1]">

Could I access that field in the POST array like this?

$_POST['myArray[0]']
$_POST['myArray[1]']

(Background: I am trying to store multiple text inputs in an array in Wordpress, but I am not able to get it working)

Jordan
  • 1,422
  • 1
  • 11
  • 21

1 Answers1

1

By html side, in the form, you can populate myArray and post it. Then by php side, you read POST as associative array. So myArray is an element of the POST array. So, that's why you access an element of myArray by php side as follows:

$POST['myArray'][0];

See https://www.php.net/manual/en/reserved.variables.post.php there are examples with multidimensional arrays too. You may find interesting this too: POST an array from an HTML form without javascript

About debug: see differences between var_dump and print_r here php var_dump() vs print_r()

GabrieleMartini
  • 1,665
  • 2
  • 19
  • 26