print outputs one expression and returns 1. echo is usually simpler for ordinary output, while print can be useful where its return value or expression-like behavior matters.
<?php
$name = 'PHP';
print 'Learning ' . $name;
print " Hello world ";
Output
Hello world
print takes one argument and always returns 1.
$first="Hello World";
print $first;
Output is here
Hello World
$first="Hello";
$second="World";
print ("$first");
print "<br>";
print ("$first $second");
Output is here
Hello
Hello World
print " Line one
Line two
One more line and end ";
Output is here
Line one Line two One more line and end
print " Welcome to \"plus2net.com\" PHP section ";
Output is here
Welcome to "plus2net.com" PHP section
$section = "PHP";
print ' Welcome to $section of plus2net';
Output is here
Welcome to $section of plus2net
We used the variable $section in above code. It will not print the value of the variable, only name will be printed.
print " Welcome to <i>plus2net</i> PHP Section " ;
Output is here
Welcome to plus2net PHP Section
Introduction to PHP echo to print string
Guide to installation and How to write our first PHP Script
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.