0
0
PHPprogramming~5 mins

Print statement in PHP

Choose your learning style9 modes available
Introduction

The print statement shows text or values on the screen. It helps you see results or messages when your program runs.

To show a welcome message to users on a webpage.
To display the result of a calculation.
To print error messages when something goes wrong.
To debug by showing variable values during development.
Syntax
PHP
print "text or value";
Use double or single quotes around text.
Each print statement ends with a semicolon (;).
Examples
Prints the text Hello, world! on the screen.
PHP
print "Hello, world!";
Prints the text PHP is fun! using single quotes.
PHP
print 'PHP is fun!';
Prints the number 123 without quotes.
PHP
print 123;
Sample Program

This program prints a welcome message, then a new line, then the number 2024.

PHP
<?php
print "Welcome to PHP programming!";
print "\n";
print 2024;
?>
OutputSuccess
Important Notes

Use \n inside double quotes to add a new line.

print is a language construct, so parentheses are optional.

Summary

Print shows text or values on the screen.

Use quotes for text, no quotes for numbers.

End each print statement with a semicolon.