Solved

Build select menus based on this array

Posted on 2008-10-18
1
181 Views
Last Modified: 2008-10-21
Ok, so I want to create the following two select menus based on the following array:

<select name="size">
<option value="X879">small / medium</option>
<option value="7ABC">small / large </option>
</select>

<select name="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Array
(
    [size] => Array
        (
			[X879] => Array
			(
				[0] => Array
				(
		            [item_id] => 32
		            [value] => small
		            [id] => 2
		            [aid] => 10
				)
				
				[1] => Array
				(
		            [item_id] => 32
		            [value] => medium
		            [id] => 2
		            [aid] => 14
				)
			)
			
			[7ABC] => Array
			(
				[0] => Array
				(
		            [item_id] => 32
		            [value] => small
		            [id] => 2
		            [aid] => 10
				)
				
				[1] => Array
				(
		            [item_id] => 32
		            [value] => large
		            [id] => 2
		            [aid] => 130 
				)
			)
        )
 
    [quantity] => Array
        (
            [options] => Array
			(
				[1] => Array
				(
					num => 1
				)
				
				[2] => Array
				(
					num => 2
				)
				
				[3] => Array
				(
					num => 3
				)
			)
        )
)

Open in new window

0
Comment
Question by:n00b0101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
sh0e earned 500 total points
ID: 22749101

//code may need cleaning up
foreach ($sel_arr as $sel_name => $opt_arr) {
	echo "<select name=\"{$sel_name}\"";
    if(strcmp($sel_name, "size")==0)
		foreach ($opt_arr as $opt_val => $opt2){
				echo "<option value=\"{$opt_val}\">{$opt2[0]['value']}/{$opt2[1]['value']}</option>";
		}
	else if(strcmp($sel_name, "quantity")==0)
		foreach ($opt_arr[options] as $opt_val => $opt_text)
			echo "<option value=\"{$opt_val}\">{$opt_text['num']}</option>";
	echo "</select>";
}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question