How To Use Echo To Print Data In PHP

ExploreEXPLORE THE CATALOGSupercharge your career with 700+ hands-on coursesView All CoursesPythonJavaJavaScriptCReactDockerVue JSRWeb DevDevOpsAWSC#LEARNING TOOLSExplore the industry's most complete learning platformCoursesLevel up your skillsSkill PathsAchieve learning goalsProjectsBuild real-world applicationsMock InterviewsNewAI-Powered interviewsPersonalized PathsGet the right resources for your goalsLEARN TO CODECheck out our beginner friendly courses.PricingFor BusinessResourcesNewsletterCurated insights on AI, Cloud & System DesignBlogFor developers, By developersFree CheatsheetsDownload handy guides for tech topicsAnswersTrusted answers to developer questionsGamesSharpen your skills with daily challengesSearchCoursesLog InJoin for freeHow to use echo to print data in PHP

In PHP, echo() is used to output one or more strings in a web browser. However, echo is not a function, rather, a language construct and can, therefore, be used with or without the parenthesis.

However, if multiple parameters are to be passed, they must not be enclosed in parenthesis as that will generate an error.

Syntax

The general syntax of echo is:

<?php echo (value);?>

Examples

Let’s take a look at some examples to see how echo works.

1. Printing a string

The following code prints a string on the browser:

<?php echo 'Hello World';?> Run

2. Printing an integer variable

Note: In order to separate two or more parameters, a comma , or a full stop . may be used.

Where $x = 5<?php $x = 5;echo 'Value of the variable is: ' , $x;echo ("\n");echo 'Value of the variable is: ' . $x;?>Run

3. Printing value from an array

The following code will demonstrate how we can print an element from an array:

Where $day[0] = 'Monday'<?php$day = array("Monday", "Tuesday", "Wednesday");echo $day[0] ; ?> Run

Relevant Answers

Explore Courses

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved

Từ khóa » E Echo Php