Q:

php: how to get POST value from the form, when the variable name is not known before the page loads?

main.php files has:
$randnum=rand(100,500);
echo '
<form name="form1" id="form1" action="my.php" method="post">
<input type="text" name="A'.$randnum.'" id="A'.$randnum.'" value="catch me!">
<input name="Submit" type="submit" value="Send">
</form>
';

browser displays:
<form name="form1" id="form1" action="my.php" method="post">
<input type="text" name="A382" id="A382" value="catch me!">
<input name="Submit" type="submit" value="Send">
</form>

How to catch "catch me!" from the form ($_POST['A382'] value)? (382 is not defined before the page was loaded). Any way to get an array of all variables that are send by POST method? Any better way?
Thank you.

A:

You can simply loop through each of the variables:
using foreach:
foreach ($_POST as $key => $value)
    echo $key . ' : ' . $value;

A:

foreach($_POST as $key=>$value)
{
    if(substr($key,0,1) == 'A')
    {
        $number = intval(substr($key, 1, 3)); //Number from A***
        if($number)
            $data = $value; //Value of field A***
    }
}

