Echo and Print Output
Output data to the browser using echo and print statements.
Output in PHP
The most common ways to send output to the browser in PHP are echo and print:
echo— language construct, outputs one or more strings, no return valueprint— language construct, outputs a single string, always returns 1- Both are not functions — you don't need parentheses
Using echo
echo is the most common output method and is slightly faster than print:
<?php
echo 'Hello, World!';
echo '<br>';
echo 'PHP', ' is', ' great'; // multiple args with comma
$name = 'Alice';
echo "Hello, $name!"; // variable interpolationAll lessons in this course
- Declaring Variables in PHP
- PHP Data Types Overview
- Echo and Print Output
- Type Juggling and Type Casting