Wrong And Rights
- March 15th, 2009
- Posted in php
- Write comment
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();
}
No comments yet.