Created
July 17, 2019 17:58
-
-
Save svpernova09/62c696cae17946c368fe3faf37b8ce82 to your computer and use it in GitHub Desktop.
PHP String Concat Options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$speed = ['quick', 'slow']; | |
$animal = ['rabbit', 'turtle']; | |
// Typical String Concatenation | |
$string = 'The ' . $speed[0] . ' ' . $animal[1] . ' jumped over the fence'; | |
// Breaking on Concatenation operator BEFORE the line exposes in each new line | |
// we're able to easily skim down the file and see we're concatenating. Also | |
// makes the variables easier to human parse | |
$string = 'The ' | |
. $speed[0] | |
. ' ' | |
. $animal[1] | |
. ' jumped over the fence'; | |
// Breaking on Concatenation operator AFTER the line: | |
// IMHO this is harder to human parse/lint | |
// This does also make the vars easy to read | |
$string = 'The ' . | |
$speed[0] . | |
' ' . | |
$animal[1] . | |
' jumped over the fence'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment