Skip to content

Instantly share code, notes, and snippets.

Flavio Biscaldi flaviors200

Block or report user

Report or block flaviors200

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@flaviors200
flaviors200 / casting.php
Created Jun 12, 2019
Casting esplicito in PHP
View casting.php
<?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)
@flaviors200
flaviors200 / foreach.php
Created Jun 10, 2019
Loop statement: foreach
View foreach.php
<?php
$colors = ['blu', 'giallo', 'verde', 'rosso', 'bianco'];
// Prima versione
foreach ($colors as $color) {
echo "$color\n";
}
// Seconda versione
@flaviors200
flaviors200 / for-optimized.php
Created Jun 10, 2019
Loop statement: for optimized
View for-optimized.php
<?php
$colors = ['blu', 'giallo', 'verde', 'rosso', 'bianco'];
for ($i = 0, $count = count($colors); $i < $count; $i++) {
echo "$colors[$i]\n";
}
/** Output **
/ blu
/ giallo
/ verde
@flaviors200
flaviors200 / for.php
Last active Jun 10, 2019
Loop statements: for
View for.php
<?php
$colors = ['blu', 'giallo', 'verde', 'rosso', 'bianco'];
for ($i = 0; $i < count($colors); $i++) {
echo "$colors[$i]\n";
}
/** Output **
/ blu
/ giallo
@flaviors200
flaviors200 / do-while.php
Last active Jun 9, 2019
Loop statements: do-while
View do-while.php
<?php
$attempts = 1;
do {
$coinFlip = random_int(0,1); // 0 testa 1 croce
echo "Lancio n. $attempts: $coinFlip\n";
$attempts--;
} while ($attempts < 10);
@flaviors200
flaviors200 / while.php
Created Jun 8, 2019
Loop statements: while
View while.php
<?php
$money = 10;
while ($money > 0) {
echo "Valore di \$money = $money\n";
$money--;
}
@flaviors200
flaviors200 / switch-statement.php
Last active Jun 6, 2019
Conditional statement: switch case
View switch-statement.php
<?php
$day = 'sabato';
switch ($day) {
case 'lunedì':
echo "Oggi è lunedì";
break;
case 'martedì':
echo "Oggi è martedì";
break;
@flaviors200
flaviors200 / ternary-operator.php
Last active Jun 4, 2019
Conditional statement: the ternary operator
View ternary-operator.php
<?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) {
@flaviors200
flaviors200 / elseif-statement.php
Last active Jun 6, 2019
Conditional statements: elseif
View elseif-statement.php
<?php
$day = 'sabato';
if ($day == 'lunedì') {
echo "Oggi è lunedì";
} elseif ($day == 'martedì') {
echo "Oggi è martedì";
} elseif ($day == 'mercoledì') {
echo "Oggi è mercoledì";
} elseif ($day == 'giovedì') {
@flaviors200
flaviors200 / else-statement.php
Last active Jun 4, 2019
Conditional statement: else
View else-statement.php
<?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
}
You can’t perform that action at this time.