displaySelect -- Convert array key-value pairs into a select input.


string displaySelect ($name, $values, $selected)

This function takes three parameters, $name, $values, and $selected. It returns an entire select input based on these three parameters.

$name is name given to the select input.

$values is an array of key-value pairs. They keys of the array become the values for the options, and the values of the array become the text of each option.

array (0 => "None") translates to <option value="0">None<option>

More key-value pairs add more options. Options are added in the order the key-value pairs appear in the array, first to last.

The 3rd parameter, $selected, is the value of a key in the array to select. In the above example, to have the "None" option selected, pass 0 to this parameter because it matches the array key for that option.

This function returns an empty select input on failure.


displaySelect ("member", array (0 => "None", 1 => "foo"), 1) /* Returns the following string: */

<select name='member'>
<option value='0'>None</option>
<option value='1' selected='selected'>foo</option>

Related Functions




Function Index