• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Build select menus based on this array

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
n00b0101
Asked:
n00b0101
1 Solution
 
sh0eCommented:

//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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now