$v){ if(!is_array($v)){ $html.=$k.'="'.$v.'" '; } } if($data_attributes && $data_attributes !== null && is_array($data_attributes)){ foreach($data_attributes as $k => $v){ if(!is_array($v)){ $html.='data-'.$k.'="'.$v.'" '; } } } return $html; }; /** * @name build_selector * Creates a html select element with options, optgroups. It marks the selected element or if * selected element is not presented, the first element. * @param array $options Source for options and optgroups * Format: * options: * - value => option * groups: * - group => array( 'groupname', array( //options ) * @param null $attributes Source for attributes * @param null $selected Value of the selected option * @throws Exception */ function build_selector($options = array(),$attributes = null,$selected = null){ $options = (!empty($options) && is_array($options)) ? $options : false; $selected = ($selected !== null && !empty($selected) && !is_array($selected)) ? $selected : false; $attributes = (!empty($attributes) && is_array($attributes)) ? $attributes : false; $data_attributes = (array_key_exists('data-',$attributes) && (!empty($attributes['data-']))) ? $attributes['data-'] : false; $html_wrapper = ' $v){ $hasChild = ( $k !== null && strtolower($k) == 'group' && is_array($v)) ? true : false; if(!$hasChild){ if($v && !empty($v)) echo ''; else echo ''; $i++; }else{ echo ''; call_user_func('create_options',$v[1], $i); echo ''; } } }; try{ var_dump($data_attributes); $attributes_html = set_attributes($attributes,$data_attributes); echo ''; create_options($options,$selected); echo ''; } catch (Exception $e){ echo "build_selector error: ".$e->getMessage(); die(1); } }; ?>