[請益] 為了reusable的pattern
大家好 小弟初學PHP
近來跟朋友開發一個web app(沒套framework)
其中有大量跟mysql撈資料的code
而這些code散佈在各個php檔
為求usable 現打算將這些code分別包成function 整理在幾份php檔內以供日後再利用
而打包成function的方式為:吃進參數、吐出array
例如:
本來這樣的code
//blah blah
while ($row = mysql_fetch_assoc($result))
{
echo($row['name']);
}
打包成
function a_cool_array(an_argument){
//blah
$cool_array = array();
while ($row = mysql_fetch_assoc($result))
{
array_push($cool_array, array("name" => $row['name']));
}
return $cool_array;
}
想請問為求reusable 這樣是不是一個好方式呢?
還是有什麼運算效能、記憶體耗用上的糟糕缺陷?
若是的話 又該怎麼追求reusable才好?
謝謝各位大大!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.231.25.170
推
04/13 11:24, , 1F
04/13 11:24, 1F
→
04/13 11:25, , 2F
04/13 11:25, 2F
→
04/13 11:25, , 3F
04/13 11:25, 3F
→
04/13 11:25, , 4F
04/13 11:25, 4F
推
04/13 11:40, , 5F
04/13 11:40, 5F
→
04/13 11:40, , 6F
04/13 11:40, 6F
→
04/13 12:05, , 7F
04/13 12:05, 7F
→
04/13 12:05, , 8F
04/13 12:05, 8F
推
04/13 12:20, , 9F
04/13 12:20, 9F
→
04/13 14:30, , 10F
04/13 14:30, 10F
PHP是5.2.17
謝謝大家的幫忙!!
※ 編輯: poopoo888888 來自: 140.112.4.170 (04/15 16:17)
→
04/24 10:09, , 11F
04/24 10:09, 11F
→
04/24 10:09, , 12F
04/24 10:09, 12F