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)

4

1 Answer 1

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()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.