0
0
PHPprogramming~5 mins

First PHP program (Hello World) - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - First PHP program (Hello World)
Start PHP script
Execute echo statement
Output: Hello World
End script
The PHP script starts, runs the echo command to print 'Hello World', then ends.
Execution Sample
PHP
<?php
echo "Hello World";
This code prints the text 'Hello World' to the screen.
Execution Table
StepActionEvaluationOutput
1Start PHP scriptN/A
2Execute echo statementecho "Hello World";Hello World
3End scriptN/A
💡 Script ends after printing 'Hello World'.
Variable Tracker
VariableStartAfter Step 2Final
No variablesN/AN/AN/A
Key Moments - 2 Insights
Why do we use <?php and ?> tags?
These tags tell the server where PHP code starts and ends, as shown in step 1 and step 3 of the execution_table.
What does the echo statement do?
Echo prints the text to the screen immediately, as seen in step 2 where 'Hello World' is output.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is printed at step 2?
ANo output
Becho "Hello World";
CHello World
DPHP code
💡 Hint
Check the Output column in row for step 2 in the execution_table.
At which step does the PHP script end?
AStep 3
BStep 2
CStep 1
DAfter Step 2
💡 Hint
Look at the Action column in the execution_table for the step labeled 'End script'.
If we remove the closing ?> tag, what happens?
AThe script will not run
BThe script still runs and prints 'Hello World'
CSyntax error occurs
DOutput will be empty
💡 Hint
PHP allows omitting the closing tag at the end of a file without error.
Concept Snapshot
<?php ... ?> tags mark PHP code start and end.
echo prints text to the screen.
This program outputs: Hello World
No variables needed.
Script runs top to bottom.
Full Transcript
This PHP program starts with the <?php tag and ends with ?>. Inside, it uses echo to print the text 'Hello World' to the screen. The execution starts by reading the PHP code, then runs the echo statement which outputs the text immediately. After that, the script ends. There are no variables used in this simple program. The closing ?> tag is optional if the PHP code is at the end of the file. This is the simplest way to write a PHP program that shows output.