Jump to content

Variable INSIDE a $_POST


ronchan

Recommended Posts

I have a very long form with input numeric names.

 

Normally I would do this to process the form:

 

$input_1005=$_POST['1005'];

$input_1006=$_POST['1006'];

 

But since there are so many inputs (over 75) I'd rather create a WHILE loop to process this form, something like:

 

$input_num=$_POST[echo $num;];

 

I know that I have the syntax wrong though.

 

Can anyone give me some help?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/141260-variable-inside-a-_post/
Share on other sites

If you create a named array variable in your form where the index of the array is your numeric value, you can use a simple foreach loop in your code to iterate over all the indexes and values.

 

Form -

<input type="text" name="arr[1005]">
<input type="text" name="arr[1006]">

 

Form processing code -

foreach($_POST['arr'] as $key => $value){
    echo "Key: $key, has value: $value<br />";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.