🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Difference Between echo and print in PHP

Echo vs. Print

  • PHP echo and print both are PHP Statements
  • Both are used to displaying the output in PHP.

What is echo

  • The echo is a statement i.e used to display the output. it can be used with parentheses echo or without parentheses echo.
  • echo can pass multiple strings separated as (,).
  • echo does,t return any value.
  • echo is faster than print.
  • It can accept multiple expressions.

Echo Example->

<?php
$channel="semicolon";
echo $channel;
echo "<br>"
Echo ($channel);
?>

For Example (pass multiple argument)

<?php
$my = "youtube devopsschool";
$channel = " channel";
$created_on=" created on 3 Oct 2018";
echo $my."".$channel."".$created_on;
?>

Now we want to print all three variable values together. all variables names are define inside the echo statement separated by comm or dot(,or.) it will show the output.

What is Print

  • It is also a statement which is used to display the output and used with the parentheses print() or without the parentheses print.
  • It cannot accept multiple expressions.
  • It is slower than echo as it return a value.
  • It cannot pass multiple argument
  • It always return the value 1.

Example-> now we want to print the name. we simply define $name inside print statement with or without parentheses.
It will show the output: “dharmu”.

<?php
$name = "dharmu";
Print $name
or
Print($name);
?>

For Example (pass multiple argument)

Declare three variable $name, $profile, $age and hold the value (“dharmu,”php developer”,25).
Now check whether it will allow executing multiple arguments.
Pass three variables inside the print statement separated by a comma. As we run this program it shows error.
It means multiple arguments are not allowed in print.

<?php
$name = "praba";
$profile = "PHP Developer";
$age = 25;
print $name,$profile,$age, "years old";
?>

Output: Parse error: syntax error

For Example (Check return type)

<?php
$name = "dharmu";
$ret = print $name;
//To test it returns or not
echo $ret;
?>

Output:
dharmu
In the above example
declare a variable $name hold value=”dharmu”.now we check the return type of print.
So (Print $name) is store in a variable ($ret).
it will show $name value with return type=1.

These other Difference Between echo and print in PHP

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.