RopeADope Posted December 13, 2010 Share Posted December 13, 2010 How can you print an individual key in the $_POST array? I've tried... echo $_POST[0]; But with no luck. There is data in the array, not all keys have values. Quote Link to comment Share on other sites More sharing options...
Adam Posted December 13, 2010 Share Posted December 13, 2010 You can check what's in the $_POST array with var_dump or print_r. Then you just need to reference the key: echo $_POST['key']); Quote Link to comment Share on other sites More sharing options...
RopeADope Posted December 13, 2010 Author Share Posted December 13, 2010 You can check what's in the $_POST array with var_dump or print_r. Then you just need to reference the key: echo $_POST['key']); Is there any way to reference a key with an index number? I'm trying to create a data processing script to handle a bunch of forms so I need to be able to reference $_POST keys without actually naming them. Quote Link to comment Share on other sites More sharing options...
Adam Posted December 13, 2010 Share Posted December 13, 2010 Not if it's an associative array. You can loop through the post array and store them in a numerically indexed array though: $array = array(); foreach ($_POST as $param) { $array[] = $param; } Quote Link to comment Share on other sites More sharing options...
RopeADope Posted December 13, 2010 Author Share Posted December 13, 2010 Ah, excellent idea. So with the code you've posted, for each loop through it will append a value to $array from $_POST, correct? Quote Link to comment Share on other sites More sharing options...
Adam Posted December 13, 2010 Share Posted December 13, 2010 Yep. You'll end up with identical values, except the associative keys will be numeric. Just remember you do loose the name, so you'll have no idea what each value is. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 13, 2010 Share Posted December 13, 2010 Ah, excellent idea. So with the code you've posted, for each loop through it will append a value to $array from $_POST, correct? I don't like loops when they're not needed $array = array_values($_POST); But I agree with MrAdam. I don't see how losing the string indexes (names) is beneficial. Probably a much better way to do what you're trying to do. Quote Link to comment 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.