PHP Switch statement


The control statement which allows us to make a decision from the number of choices is called a switch-case-default. It is almost similar to a series of if statements on the same expression.


switch (expression )
case constant1:
 execute the statement;
case constant2:
 execute the statement;
case constant3:
 execute the statement;
 execute the statement;

The expression following the keyword switch can be a variable or any other expression like an integer, a string, or a character. Each constant in  each case must be different from all others.

When we run a program containing the switch statement at first the expression following the keyword switch is evaluated. The value it gives is then matched one by one against the constant values that follow the case statements. When a match is found the program executes the statements following that case. If no match is found with any of the case statements, only the statements following the default are executed.  


In the following example $xint is equal to 3, therefore switch statement executes the third echo statement.

switch($xint) {
case 1:
echo "This is case No 1.";
case 2:
echo "This is case No 2.";
case 3:
echo "This is case No 3.";
case 4:
echo "This is case No 4.";
echo "This is default.";


This is case No 3.

View the example in the browser

Pictorial presentation of switch loop



Previous: continue statement
Next: declare statement

PHP: Tips of the Day

Convert HTML + CSS to PDF

Important: Please note that this answer was written in 2009 and it might not be the most cost-effective solution today in 2019. Online alternatives are better today at this than they were back then.

Here are some online services that you can use:

  • PDFShift
  • Restpack
  • PDF Layer
  • DocRaptor
  • HTML to PDF Rocket

Have a look at PrinceXML.

It's definitely the best HTML/CSS to PDF converter out there, although it's not free (But hey, your programming might not be free either, so if it saves you 10 hours of work, you're home free (since youalso need to take into account that the alternative solutions will require you to setup a dedicated server with the right software).

Ref : https://bit.ly/384yytr