PHP Basics
Print a value from a PHP script.
On this page
The concept
PHP variables begin with $. The echo statement writes to output; the newline character starts a new line in a terminal.
Code example
PHP
<?php
$name = "Ada";
echo "Hello, $name\n";Output
Hello, Ada
Follow the code
Open the walkthrough to inspect the example one step at a time.
Show guided walkthrough
Guided walkthroughReady
1
<?php2
$name = "Ada";3
echo "Hello, $name\n";Follow the example
Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.
View the complete dry-run table
| Step / line | What happens | State after step | Output so far |
|---|---|---|---|
| Assign Ada to the PHP variable. | $name = "Ada" | — | |
| Interpolate the variable and echo the result. | $name = "Ada" | Hello, Ada |
Behind the scenes
How PHP processes this code
The PHP runtime executes the script. echo writes to the response or terminal output.