PHP abbreviation for pre-concatenation?

I have been programming in PHP for many years, and I have always wondered if there is a way to “pre-concatenate” a string. Example:

$path = '/lib/modules/something.php';
$server = $_SERVER['DOCUMENT_ROOT'];

I have been doing this for many years to add a value to the beginning of the line:

$path = $server . $path;
// returns: /home/somesite.com/public_html/lib/modules/something.php

Is there a shortcut for this? Just curious.

+5
source share
4 answers

Not a very serious answer (I know this longer):

$path = strrev($path);
$path .= strrev($_SERVER['DOCUMENT_ROOT']);
$path = strrev($path);

There is no limit to creativity!;)

+3
source

short for concatenation interpolation :

  $path = "{$_SERVER['DOCUMENT_ROOT']}/lib/modules/something.php";
+2
source

, :

function pc(&$a, &$b) {
    $a = $b . $a;
}
pc($path, $server);

pc $path $server . $path.

+1
0

All Articles