In PHP, echo and print are language constructs used to display output in the browser. They are commonly used to print text, variables, and HTML content.
Both echo and print are not real functions, so parentheses are optional. They are frequently used to generate dynamic content in PHP pages.
Type something below to see how echo and print would handle the data.
echoCode: echo $p1, $p2;
Result:
Supports multi-params ✅printCode: print $p1, $p2;
Result:
Syntax Error ❌
// Using echo to display text and variables
";
$txt = "PHP";
echo "I love ", $txt, " programming.";
?>
// Using print to display text and a variable
";
$txt = "Print function";
print "This is a $txt example.";
?>
The above examples display simple messages in the browser. echo prints multiple values at once, while print outputs a single value and returns 1.
Switch between light and dark themes using the toggle button at the top to see how content adapts dynamically.
echo for general outputprint only when a return value is neededecho_print.phpecho and print with variableslocalhost in your browser