strutture di controllo
<?php
if ( condizione ) {
codice 1;
} else {
codice 2;
}
?>
<?php
if ( condizione ) {
codice 1;
} elseif ( condizione ) {
codice 2;
} else {
codice default;
}
?>
- <? if (strstr($HTTP_USER_AGENT,"MSIE")) { ?>
You are using Internet Explorer
<? } else { ?> You are not using Internet Explorer <? } ?>
if (strstr($HTTP_USER_AGENT,"MSIE")) { ?>
You are using Internet Explorer
} else { ?>You are not using Internet Explorer } ?>
- <? if ($last_name == ""){$last_name = '%';}?>
$last_name="";
if ($last_name == "") {$last_name = '%';} ;
print $last_name; ?>
- <? if (!$last_name){$last_name = '%';}?>
$last_name="";
if (!$last_name) {$last_name = '%';} ;
print $last_name; ?>
<?php
while ( condizione ) {
codice;
}
?>
<?php
do
{
codice;
}
while ( condizione )
?>
-
$i = 5; while ($i < 8) {
print "Oggi ho mangiato $i cioccolatini.<br>";
$i++; }
<?php
for ( espr1, espr2, espr3 ) {
codice
}
?>
-
for ($i = 5; $i < 8; $i++) {
print "Oggi ho mangiato $i cioccolatini.<br>"; }
for ($i = 5; $i < 8; $i++) {
print "Oggi ho mangiato $i cioccolatini. "; } ?>
<?php
switch ( espressione ) {
case 1:
action1;
break;
case 2:
action2;
break;
default:
defaultaction;
break;
}
?>
|