Tuesday, August 18, 2009

Read post array data

When working with the forms we are required to get all the form fields names and values at some point of time. In PHP the form values are returned in the form of array. We need to retrieve all the values in the form of pair(name,value) type.
This type of task will be used when we have hundred of variabes in a single form and we are confused with what form name the value is associated.

There are two ways to find the solutions:

1 method:

if ($_POST) {
echo htmlspecialchars(print_r($_POST, true));
}

2 Method:

foreach (array_keys($_POST) as $key) {
$$key = $_POST[$key];
print "$key is ${$key}
";
}

0 comments:

Post a Comment