'value1', 'display2' => 'value2' ) * @param array $attrs * Associative array - the key is the attribute name and the value is the value of that attribute; for example: * array ( 'class' => 'my-special-class', 'name' => 'my-element-name' ) */ public function __construct( $key_value_pairs, $attrs = null ) { // Type-checking.. if ( !is_array( $key_value_pairs ) ) { die( 'Could not construct a dropdown' ); } // Assign.. $this->key_value_pairs = $key_value_pairs; $this->attrs = $attrs; } /** * Displays this dropdown.. * @param array $attr_overrides * Associative array - the key is the attribute name and the value is the value of that attribute; * note that the keys in this array will overwrite the keys in the array that was setup at construction.. * @param mixed $selected Optional value to indicate which item is selected * @param boolean $echo Set to 'true' to echo the markup or 'false' to only return it */ public function display( $attr_overrides = null, $selected = null, $echo = true ) { // Merge the two attribute arrays.. if ( !empty( $attr_overrides ) ) { $this->attrs = array_merge( $this->attrs, $attr_overrides ); } // Create the 'select' element with the given attributes.. $markup = 'attrs as $key => $value ) { $markup .= sprintf( ' %s="%s"', $key, $value ); } $markup .= '>'; // Add the options desired.. foreach ( $this->key_value_pairs as $key => $value ) { $markup .= '