Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My list.. most of them fall more under the "hidden features" than the "favorite features" (I hope!), and not all are useful, but .. yeah. </p> <pre><code>// swap values. any number of vars works, obviously list($a, $b) = array($b, $a); // nested list() calls "fill" variables from multidim arrays: $arr = array( array('aaaa', 'bbb'), array('cc', 'd') ); list(list($a, $b), list($c, $d)) = $arr; echo "$a $b $c $d"; // -&gt; aaaa bbb cc d // list() values to arrays while (list($arr1[], $arr2[], $arr3[]) = mysql_fetch_row($res)) { .. } // or get columns from a matrix foreach($data as $row) list($col_1[], $col_2[], $col_3[]) = $row; // abusing the ternary operator to set other variables as a side effect: $foo = $condition ? 'Yes' . (($bar = 'right') &amp;&amp; false) : 'No' . (($bar = 'left') &amp;&amp; false); // boolean False cast to string for concatenation becomes an empty string ''. // you can also use list() but that's so boring ;-) list($foo, $bar) = $condition ? array('Yes', 'right') : array('No', 'left'); </code></pre> <p>You can nest ternary operators too, comes in handy sometimes.</p> <pre><code>// the strings' "Complex syntax" allows for *weird* stuff. // given $i = 3, if $custom is true, set $foo to $P['size3'], else to $C['size3']: $foo = ${$custom?'P':'C'}['size'.$i]; $foo = $custom?$P['size'.$i]:$C['size'.$i]; // does the same, but it's too long ;-) // similarly, splitting an array $all_rows into two arrays $data0 and $data1 based // on some field 'active' in the sub-arrays: foreach ($all_rows as $row) ${'data'.($row['active']?1:0)}[] = $row; // slight adaption from another answer here, I had to try out what else you could // abuse as variable names.. turns out, way too much... $string = 'f.&gt; &lt;!-? o+'; ${$string} = 'asdfasf'; echo ${$string}; // -&gt; 'asdfasf' echo $GLOBALS['f.&gt; &lt;!-? o+']; // -&gt; 'asdfasf' // (don't do this. srsly.) ${''} = 456; echo ${''}; // -&gt; 456 echo $GLOBALS['']; // -&gt; 456 // I have no idea. </code></pre> <p>Right, I'll stop for now :-)</p> <hr> <p>Hmm, it's been a while..</p> <pre><code>// just discovered you can comment the hell out of php: $q/* snarf */=/* quux */$_GET/* foo */[/* bar */'q'/* bazz */]/* yadda */; </code></pre> <p>So, just discovered you can pass any string as a method name IF you enclose it with curly brackets. You can't define any string as a method alas, but you can catch them with __call(), and process them further as needed. Hmmm....</p> <pre><code>class foo { function __call($func, $args) { eval ($func); } } $x = new foo; $x-&gt;{'foreach(range(1, 10) as $i) {echo $i."\n";}'}(); </code></pre> <p>Found this little gem in Reddit comments:</p> <pre><code>$foo = 'abcde'; $strlen = 'strlen'; echo "$foo is {$strlen($foo)} characters long."; // "abcde is 5 characters long." </code></pre> <p>You can't call functions inside {} directly like this, but you <em>can</em> use variables-holding-the-function-name and call those! (*and* you can use variable variables on it, too)</p>
    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. 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