PHP: String operator

String Operators

There are two string operators : concatenation operator ('.') and concatenating assignment operator ('.=').

Example : PHP string concatenation operator

$x = "Good";
$y = $x ." Morning";
// now $y contains "Good Morning "
echo $y;


Good Morning

View the example in the browser

Example: PHP string concatenating assignment operator

$x = "Good";
$x.= " Morning";
echo $x;


Good Morning

View the example of in the browser

Previous: Bitwise Operators
Next: Array Operators

PHP: Tips of the Day

PHP: How to get a variable name as a string in PHP?

You could use get_defined_vars() to find the name of a variable that has the same value as the one you're trying to find the name of. Obviously this will not always work, since different variables often have the same values, but it's the only way I can think of to do this.

Edit: get_defined_vars() doesn't seem to be working correctly, it returns 'var' because $var is used in the function itself. $GLOBALS seems to work so I've changed it to that.

function print_var_name($var) {
    foreach($GLOBALS as $var_name => $value) {
        if ($value === $var) {
            return $var_name;

    return false;

Edit: to be clear, there is no good way to do this in PHP, which is probably because you shouldn't have to do it. There are probably better ways of doing what you're trying to do.

Ref : https://bit.ly/37qFimU