AgerNic.com/ro
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
Tutorial

Tutorial PHP» PHP Switch

Declara?ie switch PHP
Instruc?iunea switch este utilizat? pentru a efectua diferite ac?iuni bazate pe condi?ii diferite.
Utiliza?i instruc?iunea switch pentru a selecta unul dintre numeroasele blocuri de cod care urmeaz? s? fie executate.

Sintax?:

switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;

case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}

Cum func?ioneaz?: Mai întâi avem o singur? expresie n (cel mai adesea o variabil?), care este evaluat? o singur? dat?.
Valoarea expresiei este apoi comparat? cu valorile pentru fiecare caz din structur?.
Dac? exist? o potrivire, blocul de cod asociat cu acel caz este executat. Folosi?i pauz? pentru a împiedica automat rularea codului în urm?torul caz. Instruc?iunea implicit? este utilizat? dac? nu se g?se?te nicio potrivire.

<?php
$culoare = "rosu ca focu";

switch ($culoare) {
case "rosu":
echo "Culoarea mea favorita este rosu!";
break;
case "rosu ca focu":
echo "Culoarea mea favorita este rosu ca focu!";
break;
case "albastru":
echo "Culoarea mea favorita este albastru!";
break;
default:
echo "Nu am o culoare favorita pentru carcasa mobilului meu!";
}
?>
Tags: PHP switch declaratie

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


analytics piwika