pealo86 Posted January 9, 2012 Share Posted January 9, 2012 I'm trying firstly to output hidden fields based on the values of the $_POST variable. Then after that I want to output the values again in a unordered list. I'm using the following code: while (list($key, $val) = each($_POST)) { if ($key != 'Submit') { echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />'; } } echo '<ul>'; while (list($key, $val) = each($_POST)) { if ($key != 'Submit') { echo '<li><strong>' . $key . '</strong>: <span class="highlight-219ddb">' . $val . '</span></li>'; } } echo '</ul>'; However the <ul> appears to be blank? Can I only use the list() function once on a particular variable? Quote Link to comment https://forums.phpfreaks.com/topic/254649-problem-listing-_post-values/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2012 Share Posted January 9, 2012 After each() has executed, the array cursor will be left on the next element of the array, or past the last element if it hits the end of the array. You have to use reset() if you want to traverse the array again using each. Quote Link to comment https://forums.phpfreaks.com/topic/254649-problem-listing-_post-values/#findComment-1305747 Share on other sites More sharing options...
tomfmason Posted January 9, 2012 Share Posted January 9, 2012 I would replace that while/each with a simple foreach e.g. foreach($_POST as $key=>$value) { //do some stuff } Quote Link to comment https://forums.phpfreaks.com/topic/254649-problem-listing-_post-values/#findComment-1305748 Share on other sites More sharing options...
pealo86 Posted January 9, 2012 Author Share Posted January 9, 2012 Thanks for the replies! Quote Link to comment https://forums.phpfreaks.com/topic/254649-problem-listing-_post-values/#findComment-1305768 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.