summaryrefslogtreecommitdiffhomepage
path: root/php.html.markdown
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2015-10-04 17:10:47 -0500
committerLevi Bostian <levi.bostian@gmail.com>2015-10-04 17:10:47 -0500
commit54a3d4cc7a5d49697e5547589204cf5632800823 (patch)
tree3239e3a00d2ab3c6c92360e71dfed0541418b776 /php.html.markdown
parent719e6e61327774fdef7d772c5c54f300e3b0a2b1 (diff)
parent0ad95b119d1f0135bf3a9fd55cebf24d63692c11 (diff)
Merge pull request #1292 from micheleorselli/more-php-operators
[PHP] Adds some new php operators
Diffstat (limited to 'php.html.markdown')
-rw-r--r--php.html.markdown20
1 files changed, 20 insertions, 0 deletions
diff --git a/php.html.markdown b/php.html.markdown
index 3fcce264..bc345af0 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -215,6 +215,14 @@ assert($a !== $d);
assert(1 === '1');
assert(1 !== '1');
+// spaceship operator since PHP 7
+$a = 100;
+$b = 1000;
+
+echo $a <=> $a; // 0 since they are equal
+echo $a <=> $b; // -1 since $a < $b
+echo $b <=> $a; // 1 since $b > $a
+
// Variables can be converted between types, depending on their usage.
$integer = 1;
@@ -264,6 +272,18 @@ if (false) {
// ternary operator
print (false ? 'Does not get printed' : 'Does');
+// ternary shortcut operator since PHP 5.3
+// equivalent of "$x ? $x : 'Does'""
+$x = false;
+print($x ?: 'Does');
+
+// null coalesce operator since php 7
+$a = null;
+$b = 'Does print';
+echo $a ?? 'a is not set'; // prints 'a is not set'
+echo $b ?? 'b is not set'; // prints 'Does print'
+
+
$x = 0;
if ($x === '0') {
print 'Does not print';