Is it possible to get an output like this using only 1 input?
<input name="value"/>
$_POST['value'] = 1;
$_POST['value'] = 2;
$_POST['value'] = 3;
$_POST['value'] = etc;
EDIT: I’m trying to pass an array using a single form input.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your question is a little unclear, but if you’re trying to pass an array using a single form
inputthe short answer is no, using a single element you cannot pass an array into the POST array (with the exception of the multi-select form element), but it’s easy with a tiny bit of processing once you submit. You just use a delimiter on the value and explode it in PHP:In HTML:
In PHP
This will result in:
However, there is never a way to get a PHP array to have multiple values for a single key at the same time, so you can never have a PHP array that looks like:
Because for any array (
_POSTor otherwise) $array[KEY] can not have two values (i.e. how canif ($_POST['value'] === $_POST['value'])ever not be true? It can’t, any more thatif ($x===$x)orif (1===1)can be false). You can, however, use a multi-dimensional array, which would look like:and then work with it by:
which would output