1 //generate an HTML select option tag2 functionBuild_options ($options,$opt= ",$k= ' ') {3 $frags=Array();4 if(is_string($options))5 {6 if(FALSE!==Strpos($options, ‘,‘)) {7 $options=Explode(‘,‘,$options);8}Else if(FALSE!==Strpos($options, ‘ ‘)) {9 $options=Explode(‘ ‘,$options);Ten}Else{ One return‘‘; A } - if($opt&&!In_array($opt,$options)) - { the Array_unshift($options,$opt); - } - - $options=Array_combine($options,$options); + } - if(Is_array($options)) + { A if($opt&&!In_array($opt,$options)) at { - Array_unshift($options,$opt); - } - foreach($options as $key=$val) - { - if($opt!== ' &&$k!== ' &&$key==$opt) in { - //and then there's the key in the element that was added to the K to $key=$k; + } - $frags[] =sprintf(' <option value= '%s '%s>%s</option> ',$key,$opt! = ' &&$key==$opt? ' Selected ': ',$val); the } * } $ Panax Notoginseng return implode("\ n",$frags); -}
Pass in two parameters the first one is the array the second is the column to be selected key value
If just passing in the string in such a
And if you want to pass in a key value that is not in the array, you can do this
By default, you need to select
Generate a Select selection box with a function