marți, 26 octombrie 2010

Best practice when using for sintax

Best way to use for sintax

<?php
 for($i=0;$i<$nr;++$i){ /*code*/ } 
?>

Where $nr is an integer.
Note: ++$i is way better than $i++, the reason is that $i++ creates a variable, while ++$i doesn't. So the speed of the process will be better.

PHPmaniac presents you best methods and practices!

marți, 19 octombrie 2010

Free memory usage (RAM)

When you're coding please consider the use of ressources, best way to optimize a code is to make sure that there aren't any memory leaks.

Using the command unset($variable,$var2) you can free the memory that is allocated by variable/constats.

I will give a simple example, how to use that function

<?php 
$a="something";$b="2";$c[0]="x"; $c[1]="yes";
//free memory usage
unset($a,$b,$c);
//after you used unset, $a,$b,$c will be NUL
?>

Simple and eficient!

duminică, 17 octombrie 2010

Get ip address

This is how to get an ip adress with php, included both, seerver and client.

<?php 
echo $_SERVER['REMOTE_ADDR']; //user ip
echo $_SERVER['SERVER_ADDR']; //server ip
?>