0
0
PHPprogramming~5 mins

Print statement in PHP - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Print statement
Start
Execute print statement
Output text to screen
End
The program starts, executes the print statement which sends text to the screen, then ends.
Execution Sample
PHP
<?php
print "Hello, world!";
?>
This code prints the text Hello, world! to the screen.
Execution Table
StepActionEvaluationOutput
1Execute print statementprint "Hello, world!";Hello, world!
2End of scriptNo more code
💡 Script ends after printing the text.
Variable Tracker
VariableStartAfter printFinal
No variables---
Key Moments - 2 Insights
Why does the print statement show text on the screen?
Because print sends the given string to the output immediately, as shown in execution_table step 1.
What happens if we remove the semicolon at the end?
PHP requires a semicolon to end statements; missing it causes an error and stops execution before output.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is printed at step 1?
ANo output
BHello, world!
Cprint "Hello, world!"
DError message
💡 Hint
Check the Output column in execution_table row 1.
At which step does the script finish running?
ABefore step 1
BStep 1
CStep 2
DNever ends
💡 Hint
Look at the Action column in execution_table for the end of script.
If we change the text inside print to "Hi!", what changes in the output?
AOutput changes to Hi!
BOutput stays Hello, world!
CNo output at all
DScript errors out
💡 Hint
Output depends on the string inside print, see execution_table step 1.
Concept Snapshot
PHP print statement syntax:
print "text";
Print sends text to the screen immediately.
Each statement ends with a semicolon.
Used to show messages or results.
Simple and direct output command.
Full Transcript
This example shows how PHP uses the print statement to display text on the screen. The program starts, executes the print command which outputs the string Hello, world!, then ends. The print statement requires a semicolon at the end to work correctly. Changing the text inside print changes what appears on the screen. This is the simplest way to show messages in PHP.