typestar

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

  1. Assigns a string, an integer, a float, and a bool to $-prefixed variables.
  2. echo takes comma-separated arguments; PHP_EOL ends the line.
  3. gettype names a value's type; var_dump prints type and value together.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 3 in Variables & types, step 1 of 27 in Language basics.

Next →

Variables & types in other languages