PHP Basics

Print a value from a PHP script.

PHP
<?php
$name = "Ada";
echo "Hello, $name\n";
Output
Hello, Ada

Explanation

PHP variables begin with $. The echo statement writes to output; the newline character starts a new line in a terminal.

Explore the dry run
Guided walkthroughReady
1<?php
2$name = "Ada";
3echo "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
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
Assign Ada to the PHP variable.$name = "Ada"
—
Interpolate the variable and echo the result.$name = "Ada"
Hello, Ada