Skip to content

Latest commit

 

History

History
416 lines (306 loc) · 12.4 KB

The-Basics.md

File metadata and controls

416 lines (306 loc) · 12.4 KB
layout title sitemap
page
The Basics
true

The Basics

Comparison operators

Comparison operators are an often overlooked aspect of PHP, which can lead to many unexpected outcomes. One such problem stems from strict comparisons (the comparison of booleans as integers).

{% highlight php %}

It should be noted that multiline strings can also be formed by continuing them across multilines in a statement. _e.g._ {% highlight php %} $str = " Example of string spanning multiple lines using statement syntax. $a are parsed. "; /** * Output: * * Example of string * spanning multiple lines * using statement syntax. * Variables are parsed. */ {% endhighlight %} ### Which is quicker? There is a myth floating around that single quote strings are fractionally quicker than double quote strings. This is fundamentally not true. If you are defining a single string and not trying to concatenate values or anything complicated, then either a single or double quoted string will be entirely identical. Neither are quicker. If you are concatenating multiple strings of any type, or interpolate values into a double quoted string, then the results can vary. If you are working with a small number of values, concatenation is minutely faster. With a lot of values, interpolating is minutely faster. Regardless of what you are doing with strings, none of the types will ever have any noticeable impact on your application. Trying to rewrite code to use one or the other is always an exercise in futility, so avoid this micro-optimization unless you really understand the meaning and impact of the differences. * [Disproving the Single Quotes Performance Myth](https://www.npopov.com/2012/01/09/Disproving-the-Single-Quotes-Performance-Myth.html) ## Ternary operators Ternary operators are a great way to condense code, but are often used in excess. While ternary operators can be stacked/nested, it is advised to use one per line for readability. {% highlight php %}