0

Can I pass an array inside the request parameter in php

for example

I have an hidden submit form here

<form action="" method="POST"><input type="hidden" name="myarray" value="' . $arrayofvalues . '">

can I then call the correct variable like this?

($_REQUEST['arrayofvalues[1]']
($_REQUEST['arrayofvalues[2]']

1 Answer 1

1

Yes. Just use PHP array syntax in your input name attribute:

<input type="hidden" name="myarray[]" value="<?php echo $_REQUEST['myarray'][0]; ?>">
<input type="hidden" name="myarray[]" value="<?php echo $_REQUEST['myarray'][1]; ?>">

And in PHP:

print_r($_REQUEST['myarray']);
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.