2019年5月3日 星期五

PHP Function with Optional Parameters

PHP Function with Optional Parameters

有 2 種方法

1. 用 NULL arguments
function method($arg1 = null, $arg2 = null){
  $arg1 = $arg1? $arg1: "default_value_for_arg1";
  $arg2 = $arg2? $arg2: "default_value_for_arg2";
}
2. 傳 Array
function method($arr){
  $arg1 = $arr['$arg1'] ? $arr['$arg1'] : "default_value_for_arg1";
  $arg2 = $arr['$arg2'] ? $arr['$arg2'] : "default_value_for_arg2";
}

Related Posts:

  • 網頁開發(3) 重複查詢同一資料表 對同一個資料表做重複查詢 有時候可能會對同一個資料表做重複查詢很多次 也就是需要 JOIN 兩次以上 例如( 以下範例不小心用到中文,沒試過到底可不可行 ) Table1 Table2 這時可能就需要 JOIN Table2 重複 2 次來達到完整資料 利用 AS 來達到區分 Table2 達到 JOIN 2 次的效果 SELECT send.名稱 as sendman, rec… Read More
  • CSS Selector PriorityCSS 在套用的時候,是有優先順序的。 沒研究前我以為是程式碼先後或最靠近的element <table id='table'> <tr> <td><table class='subtable'>...</table></td> <td><table class='subtable'>...</table></td>… Read More
  • Notepad++ 進階用法 Notepad++ 進階用法 列模式編輯 舉例 : 在 windows 的 cmd 下 dir > 123.txt,並用 Notepad++打開。 假如想要將時間移動欄位,按著 Alt 拉框框。 剪下,並想要的位置貼上 同步異位編輯 參考資料 : https://www.kjnotes.com/devtools/19 … Read More
  • JQuery 自動將 Listener 作用於動態新增的 ElementAdding event listeners to dynamically added elements 拿 click 舉例 $(".myclass").click(function(){ // do something }); 若在整個網頁讀取完後,才新增 class = 'myclass' 的 element 不會有這個 Event Listener 這時要用 on $('#mydiv').on('click', '… Read More
  • MySQL 利用執行順序提高效率 MySQL 利用執行順序提高效率 因為公司的內部網站平常有點慢,後來又架了個在美國的 Server 原本的小問題就被放大,雖然優化網站的方式主要不是靠 SQL的改進 最普通的優化就是不要用 SELECT * ,理由顯而易見,資料越多搜尋越慢 依照這點,所以要讓搜尋的資料越少,就要利用明確的條件去限制搜尋 也就是利用 SQL 的執行順序 SQL 的執行順序如下 : FROM ON JOIN WHERE GROUP BY WITH C… Read More

0 意見:

張貼留言

Popular Posts