PHP Echo/Print Statements

PHP Echo/Print Statements

In PHP, you can use the echo or print statements to output content to the browser or the command line. Both echo and print can be used to achieve the same result, which is displaying text or variables.

Here are some examples of using echo and print statements in PHP:

Example 1: Outputting a string using echo

php
echo "Hello, world!"; // Outputs: Hello, world!

Example 2: Outputting a string using print

php
print "Hello, world!"; // Outputs: Hello, world!

Both echo and print can also output the values of variables:

Example 3: Outputting a variable using echo

php
$name = "John";
echo "Hello, " . $name . "!"; // Outputs: Hello, John!

Example 4: Outputting a variable using print

php
$name = "John";
print "Hello, " . $name . "!"; // Outputs: Hello, John!

It’s worth noting that echo is a bit faster than print, but the difference is usually negligible. Additionally, echo can take multiple parameters separated by commas, while print only accepts a single argument.

Example 5: Using multiple parameters with echo

php
$name = "John";
$age = 25;
echo "Hello, ", $name, "! You are ", $age, " years old."; // Outputs: Hello, John! You are 25 years old.

Overall, echo and print are both useful for outputting content in PHP, and you can choose whichever one you find more convenient for your needs.

Leave a Reply

Your email address will not be published. Required fields are marked *

GLOTRU Footer
Popular Features
Popular Services/

Website Development & Design

App Development & Design

Graphic Design

Digital Marketing

SEO (Search Engine Optimization)

SMM (Social Media Marketing)

Cyber Security

Company

GLOTRU Founder & CEO : __Azam

Registared : Trade,MSME,etc

Board of Director

Team

About Us

Contact Us

Privacy Policy

Return & Refund Policy

Abuse Policy

Copyright Policy

Cookie Policy

Terms & Conditions

Universal Terms of Service

Disclaimer

Legal

Sponsorships

Investor

Press Releases

Our Investments

Brands

Newsroom

Business

...

_

Digital Millennium Copyright Act
DMCA.com Protection Status

_

Content similarity detection
Protected by Copyscape

_

***ANTI-PIRACY WARNING***

...................................................................................

Follow Us :

...................................................................................

SECURE SERVER : [Legal] [Privacy Policy] [Universal Terms of Service] [Do not sell my personal information]

SITE HOSTED : GLOTRU SECURE SERVER Asian Data Centre [You can host your site][Click Here]

SSL : Server Type : [Cloudflare] Certificate Issued By : [Let's Encrypt] Signature Algorithm : [ECDSA with SHA-384]

SITE BUILD SOFTWARE : Content Management System (CMS) Softwere

_

_

_