...

View Full Version : Accessing a form array in key=>value form



thesavior
11-02-2007, 11:14 PM
okay, I have a form with many inputs like the following:



<input type="text" name="sortorder[29]" size="1" class="admin_sortorder" value="0" />
<input type="text" name="sortorder[23]" size="1" class="admin_sortorder" value="0" />
<input type="text" name="sortorder[34]" size="1" class="admin_sortorder" value="0" />
<input type="text" name="sortorder[25]" size="1" class="admin_sortorder" value="0" />


I want to be able to access them in key=>value form. For example, i was pondering the following code:



for($_POST['sortorder'] as $key=>$value)
{
//execute w/e here.
}


How do I do something like that?

Inigoesdr
11-02-2007, 11:22 PM
Change for to foreach and it should work. You would use the $key & $value variables inside of the brackets however you wanted.

matak
11-03-2007, 12:37 AM
foreach ($_POST['sortorder'] as $key=>$value)
{
//execute w/e here.
}




that should solve your problem

thesavior
11-03-2007, 01:37 AM
thx. I guess I was thinking on the right lines then. :)

matak
11-03-2007, 01:54 AM
you sure were mate, you sure were... :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum