Re: order of elements in $_POST super global

From: Date: Thu, 08 Jun 2006 15:48:58 +0000
Subject: Re: order of elements in $_POST super global
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-237633@lists.php.net to get a copy of this message
Ben Liu wrote:
Hi Dave, No, that is definitely a possibility. Right now I am using a foreach loop to iterate over the $_POST array and determine if each checkbox is checked or not, if it is checked, than a related piece of data is written into the text file. This makes for pretty compact code. I could as you suggest, simply check each element in the array manually using the associative keys rather than using a loop, that way I could do it in any order I wished, but the code gets rather long with a line for each checkbox. I anticipate this set of checkboxes/boolean responses may increase in the future also, so having the loop allows for some future-proofing. - Ben On 6/8/06, Dave Goodchild <buddhamagnet@gmail.com> wrote:
On 08/06/06, Ben Liu <blzabub8@gmail.com> wrote:
You can access the values in the $_POST array in any order, so if you know the checkbox names why not output them in the order you want? Or I am being dumb here?
why not create an array with the keys in the order you want ( $array= array(value1,value2,....). Then loop through the array and use the values as keys to the $_POST variable and perform your processing that way. foreach ($array as $value) { if (isset($_POST[$value]) { do something; } } -- Ron Clark System Administrator Armstrong Atlantic State University

« previous php.general (#237633) next »