Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PHP manual gems

Name: Anonymous 2010-01-04 0:47

Every now and then, one comes across these mind-blowingly profound comments in the PHP manual. Post your discoveries here!

I'll start with this: (from http://www.php.net/manual/en/function.abs.php#94768)

Here is a simple function to make positives to negative and negatives to positive. This is function:

<?php
function turn($x)
     {
     $y = abs($x);
     if ($y == $x)  
         return "-$y";  
     else      
         return "$y";  
     }
?>


You can use this code:

<?php
echo turn(-5) + turn(10);
?>


The output is:

-5

;
Because 5 + -10 = -10

Name: Anonymous 2010-01-04 1:09

At the top of your page, do something to this effect:
<?php
    $n = "\n";
    $t = "\t";
?>

Then, if you need your table cell four tabs in:

<?php echo($t . $t . $t . $t . '<td>whatever</td>' . $n); ?>

This means the parser only has to interpret four characters inside double quotes, then just stores them in variables.  With strings that small, concatenating six things together won't be slow at all.


(http://www.php.net/manual/en/function.print.php#71189)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List