Re: [心得] 輸出<select>下拉選單的小撇步
※ 引述《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
討論串 (同標題文章)
完整討論串 (本文為第 2 之 3 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章