What is Interpolation in PHP

PHP supports interpolation of variables in between number  of words to be printed or to be display like  output statements echo() and  print().

In code we use single quote to define a constant string, like \’php\’ , \’constant value\’ , \’fix value\’ , while using double quote to define a string contain identifier like echo \”Price of $b is $c  total $d\” or echo \”my $a\”,Where $a,$b,$c,$d are the variable which contain value ,which is not available at the time of coding,but when we execute it on server it will return some value.

To understand how interpolation in PHP  works  we are taking an example

$a=Hello;

Now if we use double quote it look like

Example:
echo \”$a php\”; /////output will be Hello php
echo \’$a php\’; /////output will be $a php

Scroll to Top