In PHP, you can interpolate a string, substituting an object into a string. To substitute the value of a variable, you need to enclose it in double-quotes in the string. Interpolation only works with double-quoted strings. If single quotes are used in the string, then the variable's value is not interpolated, and the string will be printed as-is. In this PHP interpolation string example, we use interpolation to format a string using several variables. Click Execute to run the PHP String Interpolation Example online and see the result.
String interpolation (variable interpolation, variable substitution, or variable expansion) is the method of evaluating a string literal containing one or more placeholders, in which the placeholders are replaced with the appropriate values. In almost all languages, interpolation is preferred over concatenation for combining strings. At the same time, the string turns out to be glued, and spaces and other characters are clearly visible inside it.