Variables & types in PHP
Dollar-sign variables and the types PHP infers from their values.
<?php
$name = "typestar";
$year = 1995;
$ratio = 0.5;
$ready = true;
// every variable wears a dollar sign; the value carries the type
echo $name, " arrived in ", $year, PHP_EOL;
echo gettype($name), " and ", gettype($year), PHP_EOL;
var_dump($ratio);
var_dump($ready);
How it works
- Assigns a string, an integer, a float, and a bool to
$-prefixed variables. echotakes comma-separated arguments;PHP_EOLends the line.gettypenames a value's type;var_dumpprints type and value together.
Keywords and builtins used here
echogettypetruevar_dump
The run, in numbers
- Lines
- 11
- Characters to type
- 270
- Tokens
- 54
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 43 seconds.
Step 1 of 3 in Variables & types, step 1 of 27 in Language basics.