From 0ad95b119d1f0135bf3a9fd55cebf24d63692c11 Mon Sep 17 00:00:00 2001 From: Michele Orselli Date: Fri, 2 Oct 2015 18:24:45 +0200 Subject: adds some new php operators --- php.html.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 52ea2a95..53be5391 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'; -- cgit v1.2.3 From fb43ef2942f29ece285be3e8944c91bde6306095 Mon Sep 17 00:00:00 2001 From: Dhwani Shah Date: Fri, 2 Oct 2015 14:12:15 -0500 Subject: Added example of when string concatenation can also be helpful with combination of strings with html tags as this is important to understand when templating say output code from a database transaction. --- php.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 3fcce264..86fb14e5 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -102,6 +102,8 @@ END; // String concatenation is done with . echo 'This string ' . 'is concatenated'; +// Strings concatenation can also be combined with html elements +echo 'This string is' . '' . 'bold with strong tags ' . '.' /******************************** -- cgit v1.2.3 From 63793af2e955f8a8abe698c4a70809cfbff63452 Mon Sep 17 00:00:00 2001 From: Dhwani Shah Date: Fri, 2 Oct 2015 14:54:09 -0500 Subject: Added section on how to declare and initialize both single varible and multiple varibles with the same value. Important concept for large structured programs. Seperated this a little bit. --- php.html.markdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 86fb14e5..1c2204fd 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -101,9 +101,7 @@ $sgl_quotes END; // String concatenation is done with . -echo 'This string ' . 'is concatenated'; -// Strings concatenation can also be combined with html elements -echo 'This string is' . '' . 'bold with strong tags ' . '.' +echo 'This string ' . 'is concatenated'; /******************************** -- cgit v1.2.3 From 4e139ae2f528a08eb47427ea790bd176092e1bf0 Mon Sep 17 00:00:00 2001 From: Dhwani Shah Date: Fri, 2 Oct 2015 14:57:39 -0500 Subject: unneeded change fixed --- php.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'php.html.markdown') diff --git a/php.html.markdown b/php.html.markdown index 1c2204fd..d4131992 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -101,7 +101,7 @@ $sgl_quotes END; // String concatenation is done with . -echo 'This string ' . 'is concatenated'; +echo 'This string ' . 'is concatenated'; /******************************** @@ -689,4 +689,4 @@ If you're coming from a language with good package management, check out [Composer](http://getcomposer.org/). For common standards, visit the PHP Framework Interoperability Group's -[PSR standards](https://github.com/php-fig/fig-standards). +[PSR standards](https://github.com/php-fig/fig-standards). \ No newline at end of file -- cgit v1.2.3