PHP Output: echo vs print
Output in PHP refers to the process where text content along with HTML elements and variables gets shown in the web browser.
In PHP, the two primary functions for outputting data are:
- echo
echo Statement
Syntax
echo "Hello, world!";
Features
- Can take multiple arguments (comma-separated)
- Faster than print
- Does not return a value
print Statement
Syntax
print "Hello, world!";
Features
- Takes only one argument
- Returns 1, so it can be used in expressions
- Slightly slower than echo
Example
<?php // Using echo echo "Hello from echo!<br>"; // Using print print "Hello from print!<br>"; // echo with multiple arguments echo "PHP ", "is ", "awesome!<br>"; // print in an expression $check = print "Using print returns: "; echo $check; // Outputs: 1 ?>
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.