How to use echo command In PHP
The echo command can be used to display text, including numerical, strings and arrays.
Example 1:
<?php
$string = "w3wiki!!";
// Printing the string directly
echo ("Printing the string: ");
// Printing the variable
echo $string;
?>
Output
Printing the string: w3wiki!!
Example 2: Arrays can’t be printed directly into the script. It is compatible for displaying the data stored in string format. Therefore, the json_encode() method is used to simulate array to string conversion.
<?php
// Declaring an array
$arr = array(1, 2, 3, 4, 5);
echo('Array : ');
// Printing array
echo(json_encode($arr));
?>
Output
Array : [1, 2, 3, 4, 5]
How to display text with a PHP script ?
PHP allows us to display the text in various formats using various inbuilt methods.