Wikis & learning

Putting values on the page

A PHP statement ends at the semicolon, not at the end of a line. This receipt combines three pieces of output without first building an intermediate string.

A PHP statement ends at the semicolon, not at the end of a line. This receipt combines three pieces of output without first building an intermediate string.

Walkthrough

echo writes its arguments in order. Spaces and punctuation appear only when you put them in the strings themselves. The calculation inside parentheses creates a number, which echo displays as text.

PHP example

<?php
$item = 'Field guide';
$cost = 19;
$discount = 4;
// Price after the fixed discount.
echo $item, ' costs ', ($cost - $discount), ' credits.';

Expected output

Field guide costs 15 credits.

Change and check

Change the starting price and the discount. Then try moving the minus sign inside a quoted string and explain why the result changes.