Karaethon Posted May 7, 2019 Share Posted May 7, 2019 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/308675-echoing-all-_get-values/ Share on other sites More sharing options...
Karaethon Posted May 7, 2019 Author Share Posted May 7, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/308675-echoing-all-_get-values/#findComment-1566485 Share on other sites More sharing options...
benanamen Posted May 7, 2019 Share Posted May 7, 2019 Just use var_dump if you just need to see what the array contains. 2 Quote Link to comment https://forums.phpfreaks.com/topic/308675-echoing-all-_get-values/#findComment-1566486 Share on other sites More sharing options...
Zane Posted May 7, 2019 Share Posted May 7, 2019 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>"; 1 Quote Link to comment https://forums.phpfreaks.com/topic/308675-echoing-all-_get-values/#findComment-1566487 Share on other sites More sharing options...
chhorn Posted May 7, 2019 Share Posted May 7, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/308675-echoing-all-_get-values/#findComment-1566493 Share on other sites More sharing options...
ginerjm Posted May 7, 2019 Share Posted May 7, 2019 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? Quote Link to comment https://forums.phpfreaks.com/topic/308675-echoing-all-_get-values/#findComment-1566500 Share on other sites More sharing options...
Karaethon Posted May 8, 2019 Author Share Posted May 8, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/308675-echoing-all-_get-values/#findComment-1566527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.