Home >Backend Development >PHP Tutorial >The difference between echo, print, printf and sprintf_PHP Tutorial
- echo
is a command and cannot return a value. Echo can be followed by many parameters, separated by semicolons, such as:
echo $myvar1;
echo 1,2,$myvar,"bold";
- print
is a function that can return a value and can only have one parameter.
- printf
function, format the text and then output it, such as:
$name="hunte";
$age=25;
printf("my name is %s, age %d", $name, $age);
- sprintf
is similar to printf, but does not print, but returns formatted text, others Same as printf.
- echo
is a command and cannot return a value. Echo can be followed by many parameters, separated by semicolons, such as:
echo $myvar1;
echo 1,2,$myvar,"bold";
- print
is a function that can return a value and can only have one parameter.
- printf
function, format the text and then output it, such as:
$name="hunte";
$age=25;
printf("my name is %s, age %d", $name, $age);
- sprintf
is similar to printf, but does not print, but returns formatted text, others Same as printf.