Scrigroup - Documente si articole

     

HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

Tutorial - Introduction to Switches

php



+ Font mai mare | - Font mai mic



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



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 823
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved