Skip to content

Instantly share code, notes, and snippets.

@svpernova09
Created July 17, 2019 17:58
Show Gist options
  • Save svpernova09/62c696cae17946c368fe3faf37b8ce82 to your computer and use it in GitHub Desktop.
Save svpernova09/62c696cae17946c368fe3faf37b8ce82 to your computer and use it in GitHub Desktop.
PHP String Concat Options
<?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