Jump to content
Karaethon

Echoing all $_GET values

Recommended Posts

I am testing my app to server transport to verify everything is working, I need to write a loop that takes each value sent via GET and/or POST and then echo each key:value back, how do I step through the $_GET or $_POST and extract each to echo?

Something like this, but what?

<?php
/*I know this is not valid, is psedocoded*/
foreach($key in $_GET as $value){
  echo $key." = ".$value;
}
?>

 

Share this post


Link to post
Share on other sites

Ok, I was almost right on. I got it right except my foreach order was wrong.

<?php
foreach($_GET as $key => $value){
	echo $key." = ".$value;
}
?>

is the correct way. sorry for wasting space on the forum.

Share this post


Link to post
Share on other sites

Just use var_dump if you just need to see what the array contains.

  • Like 2

Share this post


Link to post
Share on other sites

I always use this snippet to debug my code / echo out the contents of an array or object or any object type.  It takes a mixed type parameter, print_r

echo "<pre>", print_r($_GET), "</pre>";

 

  • Like 1

Share this post


Link to post
Share on other sites

i would always recommend using var_dump() because it also shows info on null, boolean and empty string values. At least you can also use json_encode() for this, but it lacks on objects.

Share this post


Link to post
Share on other sites

Rather that being focused on this debugging process, how about setting up what appears to be necessary data input validation to be sure that all the array values exist?

Share this post


Link to post
Share on other sites

I wasn't debugging so much as trying to verify that the app code was sending valid $_GET parameters. The app does all the data valiation, and I verified that side, I just needed to double check that what I 'thought' was being transmitted was what was actually being recieved. I don't have access to the recieving server so I was submitting to localhost to verify before actually submitting to server.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.