Wrong And Rights
Switch statements:
// Always assume that the case got not catched
// Wrong
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
}
// Good
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
default:
// Always assume that the case got not catched
break;
}
Operations in loop definition:
// On every iteration the sizeof function is called
for ($i = 0; $i < sizeof($post_data); $i++)
{
do_something();
}
// You are able to assign the (not changing) result within the loop itself
for ($i = 0, $size = sizeof($post_data); $i < $size; $i++)
{
do_something();
}
This entry was posted on Sunday, March 15th, 2009 at 7:37 pm and is filed under php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
