Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

if else cascade alternative - switch hack

1
2
3
4
5
<?php
switch (true) {
  case test1==test2: ... break;
  case x1 > 14: ... break;
}
https://snipt.net/embed/5aca48442003c24db971af7e0bb5b3ac/
https://snipt.net/raw/5aca48442003c24db971af7e0bb5b3ac/
5aca48442003c24db971af7e0bb5b3ac
php
PHP
5
2016-12-02T16:33:03
True
False
False
/api/public/snipt/34713/
if-else-cascade-alternative-switch-hack
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">switch</span> <span class="p">(</span><span class="k">true</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">case</span> <span class="nx">test1</span><span class="o">==</span><span class="nx">test2</span><span class="o">:</span> <span class="o">...</span> <span class="k">break</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">case</span> <span class="nx">x1</span> <span class="o">&gt;</span> <span class="mi">14</span><span class="o">:</span> <span class="o">...</span> <span class="k">break</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
cascade, else, if, ifelse, switch
Copyrighted, illegal, or inappropriate content? Email [email protected].