0

I have an Array $_POST['size']

I want to pass this on to the next page

at first i thought, well thats easy just pass it:

<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>"/>

obviously this is wrong but is there a way to do it without doing this:

foreach ($_POST['size'] as $key => $value){
 echo '<input type="hidden" name="size['.$key.']" value="'.$value.'"/>';
}

2 Answers 2

1

Use sessions - this is a perfect example as to why.

Store $_POST['size'] in $_SESSION['size'] and get it from the session on the page you need it.

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

Comments

1

You could json_encode the array (as the value in the hidden element), and then json_decode in the next PHP page

1 Comment

I don't think it matters, echo '<input type="hidden" name="arrayName" value="'.json_encode($_POST['size']).'"/>'; would be the same result as encoding it first. You could also write to a cookie if you'd like a bit more persistance

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.