title: How to shorten the code where are multiple if statements?
body: <p>I was thinking about this some time. I'm using a lot if statements, and sometimes I have a lot of them. I know I can use <code>switch</code> to shorten a bit the code. Is there another way to shorten them?</p>
  
  <p>Let's say we have this example:</p>
  
  <pre class="lang-php prettyprint-override"><code>$all_conditions = '';
  
          if($post_status != ""){
              $conditions[] = "posts.post_status = '".$post_status."'";
          }
          if($post_type != ""){
              $conditions[] = "posts.post_type = '".$post_type."'";
          }
          if($meta_key != ""){
              $conditions[] = "postmeta.meta_key = '".$meta_key."'";
          }
          if($meta_value != ""){
              $conditions[] = "postmeta.meta_value = '".$meta_value."'";
          }
          if($date_begin != "" &amp;&amp; $date_end != ""){
              $conditions[] = "( posts.post_date BETWEEN '".$date_begin."' AND '".$date_end."' )";
          }
          if(count($conditions)&gt;0){
              $all_conditions = implode(" AND ",$conditions);
          }
          if($all_conditions != ""){
              $all_conditions = "WHERE ".$all_conditions;
          }
  </code></pre>
  
  <p>What should I do to not repeat all those if's?</p>