CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
Tutorial - Introduction to Switches
Switches are very useful alternatives to really big if statements.
There isn't much of an introduction here, we'll jump right into them in detail.
switch ($a)
The first line:
switch ($a) ) is the same as break statement
} elseif ($a == 'b') ) is the same as break statement
} else
With our example, there's not a lot of difference, but when you get a few cases to test and each case needs lots of different
processing, using a switch makes sense, and looks cleaner (and easier to read).
Another handy feature of switches is to get multiple cases to do the same thing. How? By leaving out the 'break'
statements. So:
switch ($a)
will do the same for $a when it has the value of 'a' and 'b'.
How do we use them in a script? Anywhere where you either set a value, or values are set specifically (for example, radio
buttons).
Here's a simple script to test our switch:
<?php
$a = 'a';
switch ($a)
?>
Change the value of $a to test the switch. Pretty simple!
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 808
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved