String interpolation in PHP
Double quotes splice variables into strings; single quotes leave them alone.
<?php
$name = "typestar";
$letters = 8;
// double quotes interpolate; single quotes stay literal
echo "$name has $letters letters\n";
echo 'literal: $name has $letters letters', "\n";
// braces mark off array lookups and other expressions
$langs = ["php", "ruby"];
echo "first up: {$langs[0]}\n";
echo "shouted: " . strtoupper($name) . "\n";
How it works
"$name has $letters letters"interpolates both variables in place.- The single-quoted twin prints the dollar signs literally.
- Braces as in
{$langs[0]}mark off array lookups inside a string. .concatenates when the value comes from a call likestrtoupper.
Keywords and builtins used here
echostrtoupper
The run, in numbers
- Lines
- 12
- Characters to type
- 343
- Tokens
- 66
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 57 seconds.
Step 2 of 3 in Variables & types, step 2 of 27 in Language basics.