Skip to content

Instantly share code, notes, and snippets.

View flaviors200's full-sized avatar

Flavio Biscaldi flaviors200

View GitHub Profile
@flaviors200
flaviors200 / integer.php
Last active May 22, 2019 16:50
Integer data type
<?php
$dec = 40; // decimale
$oct = 0321; // ottale
$hex = 0xBC; // esadecimale
$bin = 0b11111; // binario
$neg = -125;
echo $dec."\n"; // 40
echo $oct."\n"; // 209
echo $hex."\n"; // 188
@flaviors200
flaviors200 / float.php
Last active May 15, 2019 23:45
Float data type
<?php
$float = 123.30;
$float2 = 120e-3; // Sintassi con esponente
echo $float."\n";
echo $float2;
/*
Output
@flaviors200
flaviors200 / string.php
Created May 16, 2019 00:26
String data type
<?php
$car = "Ferrari";
$model = 'F40';
echo "Auto $car \n";
echo "Modello $model\n";
/*
Output
@flaviors200
flaviors200 / string-as-array.php
Last active May 16, 2019 17:09
String as array
<?php
$lastName = "Biscaldi";
echo $lastName[0];
echo $lastName[3];
echo $lastName[4];
// Output Bca
@flaviors200
flaviors200 / string-functions.php
Last active May 16, 2019 17:51
String functions
<?php
$string = "Ciao mondo!";
echo strlen($string)."\n"; // Output 11
echo strpos($string, 'mondo')."\n"; // Output 5
echo substr($string, 5, 5)."\n"; // Output mondo
echo str_replace('mondo', 'a tutti', $string)."\n"; // Output Ciao a tutti
@flaviors200
flaviors200 / assignment-operators.php
Last active May 22, 2019 23:15
Assignment operators
<?php
$x = 30;
echo $x."\n"; // Output: 30
$x += 30;
echo $x."\n"; // Output: 60
$x -= 20;
echo $x."\n"; // Output: 40
@flaviors200
flaviors200 / arithmetic-operators.php
Created May 23, 2019 09:20
Arithmetic Operators
<?php
$x = 9;
$y = 2;
echo $x + $y; // 0utput: 11
echo $x - $y; // 0utput: 7
echo $x * $y; // 0utput: 18
echo $x / $y; // 0utput: 4.5
echo $x % $y; // 0utput: 1
@flaviors200
flaviors200 / comparison-operators.php
Last active May 23, 2019 09:56
Comparison operators
<?php
$x = 10;
$y = "10";
var_dump($x == $y); // Output: boolean true
var_dump($x === $y); // Output: boolean false
var_dump($x != $y); // Output: boolean false
var_dump($x !== $y); // Output: boolean true
var_dump($x < $y); // Output: boolean false
var_dump($x > $y); // Output: boolean false
@flaviors200
flaviors200 / logical-operators.php
Last active June 4, 2019 10:55
Logical operators
<?php
$score = 300;
if ($score >= 200 && $score <= 400) {
echo "Hai vinto il peluche medio";
}
@flaviors200
flaviors200 / bitwise-operators.php
Last active May 28, 2019 23:05
Bitwise operators
<?php
$x = 127; // 1111111
$y = 85; // 1010101
var_dump(decbin($x & $y)); // Output: string(7) 1010101
var_dump(decbin($x | $y)); // Output: string(7) 1111111
var_dump(decbin($x ^ $y)); // Output: string(6) 101010
var_dump(decbin(~ $x)); // Output: string(64) 1111111111111111111111111111111111111111111111111111111110000000
var_dump(decbin($x << 1)); // Output: string(8) 11111110