Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Or any performance wise difference between two??</p> </blockquote> <p>Forget about the performance difference on this level- there may be a microscopic one, but you'll feel it only when doing hundreds of thousands of operations, if at all. <code>switch</code> is a construct for better code readability and maintainability: </p> <pre><code>switch ($value) { case 1: .... break; case 2: .... break; case 3: .... break; case 4: .... break; case 5: .... break; default: .... break; } </code></pre> <p>is mostly much more clean and readable than</p> <pre><code>if ($value == 1) { .... } elseif ($value == 2) { .... } elseif ($value == 3) { .... } elseif ($value == 4) { .... } elseif ($value == 5) { .... } else { .... } </code></pre> <p><strong>Edit:</strong> Inspired by Kuchen's comment, for completeness' sake some <a href="http://www.phpbench.com/" rel="noreferrer">benchmarks</a> (results will vary, it's a live one). Keep in mind that these are tests that run <strong>1,000 times</strong>. The difference for a couple of <code>if</code>'s is <strong>totally negligeable</strong>.</p> <ul> <li>if and elseif (using ==) <strong>174 µs</strong> </li> <li>if, elseif and else (using ==) <strong>223 µs</strong></li> <li>if, elseif and else (using ===) <strong>130 µs</strong></li> <li>switch / case <strong>183 µs</strong></li> <li>switch / case / default <strong>215 µs</strong></li> </ul> <blockquote> <p><strong>Conclusion (from phpbench.com)</strong>:</p> <p>Using a switch/case or if/elseif is almost the same. Note that the test is unsing === (is exactly equal to) and is slightly faster then using == (is equal to).</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload