問題標題可能不能證明我的問題的功能,因爲在所有我不知道寫什麼作爲標題。創建重複否則,如果
所以,如果我有這樣的事情:
if($type=="a"){
$s.= " AND type= 'List Apart ";
}elseif($type=="b"){
$s.= " AND type = 'Before CSS3' ";
}elseif($type=="C"){
$s.= " AND type = 'Tricks' ";
}elseif($type=="D"){
$s.= " AND type = 'Stackoverflow' ";
.. etc until Z (just for example)
所以我能做到這一點?我試過了,但它不起作用。
$arr = array("b"=>"Before CSS3",..."Z"=>"Somethingd"); // it's not just a simple a-z. A is hardcoded because of the if.
foreach($arr as $r){
$r.= "}elseif($type=='key($r)'){ //not the syntax cos I kinda forget :p
$s.= ' AND type = \'value($r)\' "; //same here
}
return $r;
更新:對不起,如果我不夠清楚,我已經編輯了我的問題。因此,它不只是一個簡單的A-Z環,它與鍵和值的數組。