user2280440
user2280440

Reputation: 1

array inside Request Parameter php

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]']

Upvotes: 0

Views: 49

Answers (1)

John Conde
John Conde

Reputation: 219834

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']);

Upvotes: 1

Related Questions