This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$var1 = 10; | |
$var2 = 6.5; | |
var_dump($var1 + $var2); // Output: float(16.5) | |
$var2 = (int) 6.5; | |
var_dump($var1 + $var2); // Output: int(16) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$colors = ['blu', 'giallo', 'verde', 'rosso', 'bianco']; | |
// Prima versione | |
foreach ($colors as $color) { | |
echo "$color\n"; | |
} | |
// Seconda versione |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$colors = ['blu', 'giallo', 'verde', 'rosso', 'bianco']; | |
for ($i = 0, $count = count($colors); $i < $count; $i++) { | |
echo "$colors[$i]\n"; | |
} | |
/** Output ** | |
/ blu | |
/ giallo | |
/ verde |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$colors = ['blu', 'giallo', 'verde', 'rosso', 'bianco']; | |
for ($i = 0; $i < count($colors); $i++) { | |
echo "$colors[$i]\n"; | |
} | |
/** Output ** | |
/ blu | |
/ giallo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$attempts = 1; | |
do { | |
$coinFlip = random_int(0,1); // 0 testa 1 croce | |
echo "Lancio n. $attempts: $coinFlip\n"; | |
$attempts--; | |
} while ($attempts < 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$money = 10; | |
while ($money > 0) { | |
echo "Valore di \$money = $money\n"; | |
$money--; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$day = 'sabato'; | |
switch ($day) { | |
case 'lunedì': | |
echo "Oggi è lunedì"; | |
break; | |
case 'martedì': | |
echo "Oggi è martedì"; | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$year = 2020; | |
echo ($year % 4 == 0) ? "$year è un'anno bisestile" : "$year non è un'anno bisestile"; | |
// Output: 2020 è un'anno bisestile | |
/******* Forma normale ********/ | |
/* | |
/* if ($year % 4 == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$day = 'sabato'; | |
if ($day == 'lunedì') { | |
echo "Oggi è lunedì"; | |
} elseif ($day == 'martedì') { | |
echo "Oggi è martedì"; | |
} elseif ($day == 'mercoledì') { | |
echo "Oggi è mercoledì"; | |
} elseif ($day == 'giovedì') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 10; | |
$y = 14; | |
if ($x > $y) { | |
echo "$x è maggiore di $y"; | |
} else { | |
echo "$x è minore o uguale di $y"; // Output: 10 è minore o uguale di 14 | |
} |
NewerOlder