Posts Tagged ‘variables array’

Getting all _post or _get variables, array or per 1

Share on TwitterShare on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to redditShare on MyspaceShare via email

By default, all forms submitted values, whether by method=get or method=post

It will result in 1 global variable

$_POST  or $_GET

With the $_post array
if(isset($_post['variable_in_question'])) echo “yea”;
This is supposing you know the variable
Or simply printing it out or adding it to variable as in

$myvar = $_POST[variable_in_question];

Elsewhere, if you do not know all variables coming in, or you want to print out all posted or got items from a form, here is how to put them in an array :

Simplest print method to know what are the printed variables is
echo ‘<pre>’;
print_r($_post);
echo ‘</pre>’;

To array those variables :
foreach ($_POST as $var => $value) {
echo “$var = $value<br>n”;
}

In my example,  i wanted to re-create a link, with the posted information, so what i did was:

foreach ($_GET as $var => $value) {
echo “$var=$value&”;
}
$myurl=”http://wwwDOTexampleDOTcom/main.php?$var”

That was since i was going to repull another link with same variables from unknown coming post items.
ps: switch get or post according to your predefined form method.



Share on TwitterShare on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to redditShare on MyspaceShare via email