PHP echo

The PHP echo statement is a language construct that is used to output text or HTML code to the browser. It is one of the most commonly used statements in PHP and is used to display data, such as text, variables, and arrays, to the user. The basic syntax of the echo statement is as follows:

echo expression;

Here, the expression can be a string, a variable, or any other PHP expression that evaluates to a value. The echo statement can also be used to output multiple expressions separated by commas. For example:

echo "Hello, ", $name, "!";

In this example, the echo statement outputs the string “Hello, ” followed by the value of the $name variable and the string “!”.

The echo statement can be used in a variety of ways. Here are some common examples:

  1. Outputting Text
echo "Hello, World!";

In this example, the echo statement outputs the string “Hello, World!” to the browser.

  1. Outputting Variables
$name = "John";
echo "My name is " . $name . ".";

In this example, the echo statement outputs the string “My name is John.” to the browser. The value of the $name variable is concatenated with the rest of the string using the dot (.) operator.

  1. Outputting HTML
echo "<h1>Hello, World!</h1>";

In this example, the echo statement outputs the HTML code for an <h1> heading tag to the browser.

  1. Outputting Arrays
$fruits = array("apple", "banana", "orange");
echo "I like " . $fruits[0] . "s.";

In this example, the echo statement outputs the string “I like apples.” to the browser. The value of the first element in the $fruits array is concatenated with the rest of the string.

In conclusion, the PHP echo statement is a powerful tool for outputting text, variables, and HTML to the browser. By using the echo statement appropriately, developers can create dynamic and interactive web pages that provide users with relevant information.

<?php
echo "Welcome to w3htmlschool online tutorials";
echo "This is an Echo Example";
?>