PHP echo and print

echo and print are used in PHP to output text, variables, and HTML to the browser.

Example:
<?php
    echo "Hello World!";   // Output using echo

    echo "This ", "is ", "PHP.";   // echo can output multiple strings

    print "Hello PHP!";    // Output using print

    $result = print "Test";   // print returns 1
?>

👉 Explanation:

  • echo → Faster, can output multiple values, does not return anything.
  • print → Outputs one value at a time and always returns 1.
  • Both are used to display strings, HTML, and variables in PHP.
PHP Tutorial