Jump to content

Which way is the best?


Kryllster

Recommended Posts

I have some code / code blocks concerning case block and have basically 2 questions. First which of these is the correct way to write a case block or which is the best.

1.

case main;
include('somefile.php');
break;

 

2

case: 'main';
include('somefile.php');
break;

 

3.

case "main";
include("somefile.php");
break;

 

which leads to the next question when do you use double quotes and when do you use single quotes? If it really doesnt matter. then I guess it should be pretty uniform across documents etc..

Link to comment
https://forums.phpfreaks.com/topic/159806-which-way-is-the-best/
Share on other sites

I say none of them.

 

case 'main':
     include('somefile.php');
     break;

 

See the colon instead of the semi-colon? If you use a semi-colon, your include statement will always run regardless. There isn't a general rule on when to use double quotes or single quotes. If you must use variable interpolation, then double quotes. I tend to start with single quotes and use double quotes for HTML attributes. But speed difference, almost the same.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.