Re: [心得] 輸出<select>下拉選單的小撇步

看板PHP作者 (這年頭,閃光都不閃了..)時間17年前 (2008/06/23 15:29), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《lgzenith (封影)》之銘言: : 照個人喜好修改一下 : function make_select($array,$default_key=null,$attributes=null){ : $htm = "<select $attribuges >"; : $str = '<option value="%s"%s>%s</option>'; : foreach($array as $key=>$text){ : $sel = ''; : if ($key == $default_key){ : $sel = ' selected="selected"'; : }else{ : $sel = ''; : } : printf($str, $key, $sel, $text ); : } : $htm .= '</select>'; : return $htm; : } : 後來比較喜歡用這種方式,我個人認為比較容易讀,因為以前"$xxx".'xxx'這種寫法 : 我看起來實在是很不舒服。 : 還有就是盡量照網頁標準寫法來 : 到現在都還沒有吃午餐,為什麼我還在寫程式= = 如果有用 Smarty 的話... 也可以參考這個.. http://www.smarty.net/manual/en/language.function.html.options.php 若是你用的是 date, date time 的話... http://www.smarty.net/manual/en/language.function.html.select.date.php http://www.smarty.net/manual/en/language.function.html.select.time.php -- 我是上來領便當的... 逛 php 版, database 版只是順便而已... http://blog.darkhero.net 個人網誌 http://phorum.study-area.org/index.php/board,31.0.html 公司缺人 PHP 網站程式設計師(中初階學徒可), 熟 MVC 尤嘉~ 請發站內信給我... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.210.124
文章代碼(AID): #18Nr36Sm (PHP)
文章代碼(AID): #18Nr36Sm (PHP)