Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-02-2007, 11:14 PM   PM User | #1
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
Accessing a form array in key=>value form

okay, I have a form with many inputs like the following:

Code:
<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:

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

How do I do something like that?
thesavior is offline   Reply With Quote
Old 11-02-2007, 11:22 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Change for to foreach and it should work. You would use the $key & $value variables inside of the brackets however you wanted.
Inigoesdr is offline   Reply With Quote
Old 11-03-2007, 12:37 AM   PM User | #3
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
PHP Code:
foreach ($_POST['sortorder'] as $key=>$value)
{
//execute w/e here.



that should solve your problem
matak is offline   Reply With Quote
Old 11-03-2007, 01:37 AM   PM User | #4
thesavior
Senior Coder

 
Join Date: Aug 2005
Posts: 1,119
Thanks: 2
Thanked 1 Time in 1 Post
thesavior has a little shameless behaviour in the past
thx. I guess I was thinking on the right lines then.
thesavior is offline   Reply With Quote
Old 11-03-2007, 01:54 AM   PM User | #5
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
you sure were mate, you sure were...
matak is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:24 PM.


Advertisement
Log in to turn off these ads.