Question:

What is the purpose of the echo statement in PHP?

Show Hint

In PHP, both `echo` and `print` can be used to display output. `echo` is slightly faster as it is a language construct and doesn't return a value, while `print` is a function that returns 1. `echo` can also take multiple arguments.
Updated On: Jul 2, 2026
  • store data in a database
  • execute JavaScript code
  • display output on a webpage
  • To comment on code
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

PHP is a server-side scripting language primarily used for web development. A PHP script is executed on the server, and its output is sent to the client's browser, typically as HTML.
The `echo` construct is one of the primary ways in PHP to output data. It can output one or more strings, variables, or the result of expressions. This output becomes part of the HTML document that is sent to the browser.
Let's analyze the options:
(A) Storing data in a database is done using database functions (e.g., with MySQLi or PDO).
(B) PHP runs on the server and generates HTML. If you `echo` JavaScript code, that code will be sent to the browser and then executed by the browser, but `echo`'s purpose is simply to output the string, not to execute it.
(C) This is the core purpose. `echo "<h1>Hello World</h1>";` will cause the text "Hello World" to be displayed as a heading on the final webpage.
(D) Comments in PHP are made using `//`, `#`, or `/ ... /`.
Therefore, the purpose of `echo` is to display output.
Was this answer helpful?
0
0