Any equivalent to .= for adding to beginning of string in PHP?

Nope. But you can do

$foo = "bar" . $foo

You could always make your own function for that:

function prepend($string, $chunk) {
     if(!empty($chunk) && isset($chunk)) {
        return $string.$chunk;
     }
     else {
        return $string;
     }
}

$string would be the piece that you want to prepend and $chunk would be the text that you want something prepended onto it.

You could say the checks are optional, but by having that in there you don't need to worry about passing in a null value by accident.

Tags:

Php