-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_dropdown.php
More file actions
30 lines (23 loc) · 1020 Bytes
/
Copy pathmulti_dropdown.php
File metadata and controls
30 lines (23 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
function multi_dropdown( $name, array $options, array $selected=null, $size=4 )
{
/*** begin the select ***/
$dropdown = '<select name="'.$name.'" id="'.$name.'" size="'.$size.'" multiple>'."\n";
/*** loop over the options ***/
foreach( $options as $key=>$option )
{
/*** assign a selected value ***/
$select = in_array( $option, $selected ) ? ' selected' : null;
/*** add each option to the dropdown ***/
$dropdown .= '<option value="'.$key.'"'.$select.'>'.$option.'</option>'."\n";
}
/*** close the select ***/
$dropdown .= '</select>'."\n";
/*** and return the completed dropdown ***/
return $dropdown;
}
$name = 'multi_dropdown';
$options = array( 'dingo', 'wombat', 'kangaroo', 'steve irwin', 'wallaby', 'kookaburra' );
$selected = array( 'dingo', 'kangaroo', 'kookaburra' );
echo multi_dropdown( $name, $options, $selected );
?>