pass array values in a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dimitris83
Forum Newbie
Posts: 2
Joined: Fri Sep 02, 2005 5:18 pm

pass array values in a form

Post by dimitris83 »

Hello!
Well I have this problem, I have an array and I want to pass all the values of this array in a form object ( a drop down list for example). I can't find how can I do this, I can only pass the values one by one, but the problem is that I don't know how many values I will have.
Any suggestions? :?:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$array = array('value1', 'value2', 'value3');

$html = '<select name="some_name">';
foreach ($array as $element) {
   $html .= '<option value="'.$element.'>'.$element.'</option>';
}
$html .= '</select>';
foreach()
dimitris83
Forum Newbie
Posts: 2
Joined: Fri Sep 02, 2005 5:18 pm

Post by dimitris83 »

Thanks my friend!! You are great (and very quick :D )
Post Reply