create a function of a repetitive else if
<p>the question title might not justify my question at all since I have no idea what to write as the title.</p>

<p>So, if I have something like this:</p>

<pre><code>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)
</code></pre>

<p>So can I do this? I've tried it but it doesn't work.</p>

<pre><code>$arr = array("b"=&gt;"Before CSS3",..."Z"=&gt;"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;
</code></pre>

<p>UPDATE : Sorry if I was not being clear enough, I've already edited my question. So it's not just a simple a-z loop, it's an array with keys and values.</p>
